Private Sub MyDataGrid_CellEnteredEditMode(ByVal sender As Object, ByVal e As EditingCellEventArgs)
' Ensure correct cell
If (e.Cell.Column.Key = "ProductName") Then
Dim box As ComboBox = CType(e.Editor, ComboBox)
box.ItemsSource = DataUtil.Products
' Set selected index to the index of the grid cell
box.SelectedIndex = e.Cell.Row.Index
End If
End Sub
Private Sub MyDataGrid_CellExitingEditMode(ByVal sender As Object, ByVal e As ExitEditingCellEventArgs)
' Ensure using correct cell and editing has not been cancelled
If ((e.Cell.Column.Key = "ProductName") _
AndAlso Not e.EditingCanceled) Then
Dim box As ComboBox = CType(e.Editor, ComboBox)
If (Not (box.SelectedItem) Is Nothing) Then
' New value is value of selected item in combo box
e.NewValue = CType(box.SelectedItem, Product).ProductName
box.ItemsSource = Nothing
box.SelectedItem = Nothing
End If
End If
End Sub