Recently I use radgridview and gridViewComboBoxColumn to achieve the goal that users could be insert or update database by dropping down the combobox. How can I get the selected-value to operate the database? My codes are listed as below. May you give me some hints? Thank you.
XAML Code:
<telerik:RadGridView x:Name="gv1"
Grid.Row="1"
Margin="5"
AlternationCount="2"
AutoGenerateColumns="False"
FontSize="{Binding Source={x:Static local:MySettings.Default},
Path=FontSize,
Mode=OneWay}"
IsFilteringAllowed="False"
SelectionUnit="FullRow"
ShowGroupPanel="False"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding opc_id}"
Header="opc_id"
IsReadOnly="False" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding ip_address}"
Header="ip_address"
IsReadOnly="False" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding hmi_user}"
Header="hmi_user"
IsReadOnly="False" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding description}"
Header="description"
IsReadOnly="False" />
<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding entry_area}"
DisplayMemberPath="description"
Header="entry_area"
IsReadOnly="False"
SelectedValueMemberPath="Id"
UniqueName="entry_area" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>"
VB.NET CODE:
Private Sub gv1_RowEditEnded(sender As Object, e As Telerik.Windows.Controls.GridViewRowEditEndedEventArgs) Handles gv1.RowEditEnded
If e.EditAction = GridViewEditAction.Cancel Then
Exit Sub
End If
If e.EditOperationType = GridViewEditOperationType.Insert Then
'Add the new entry to the data base.
Dim opc As New OPC_Profile With {.opc_id = TryCast(e.Row.Cells(0).Content, TextBlock).Text, _
.ip_address = TryCast(e.Row.Cells(1).Content, TextBlock).Text, _
.hmi_user = TryCast(e.Row.Cells(2).Content, TextBlock).Text, _
.description = TryCast(e.Row.Cells(3).Content, TextBlock).Text, _
.entry_area = TryCast(e.Row.Cells(4).Content, LookupElement).ComboBox.Text}
End If