Dim datatable_default_view As DataTable = _datatable.DefaultView.ToTable
Dim servicenumber As String = datatable_default_view.Rows.Item(e.RowIndex)("Service Number").ToString
'gets the service number of the selected row
If _datatable.PrimaryKey.Length = 0 Then
Dim keys(0) As DataColumn
keys(0) = _datatable.Columns("Service Number")
_datatable.PrimaryKey = keys
End If
Dim datarow_edited As DataRow = _datatable.Rows.Find(servicenumber)
Try
MsgBox("Record" + datarow_edited("service number") + " was edited")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Error")
End Try
I’ve put this code under the DatagridView_CellEndEdit event
The Problem:
The ‘data_row edited’ variable doesn’t get initialized when exiting the cell in edit mode using the keyboard (ie: pressing the down/up arrow).
If I use the mouse it works as expected. Why is this ? Is it a known bug I’m using VB.net 2008. Please Help
I’ve uploaded a sample project, with sample data here. Check it out if possible.
Just tried you example solution with VS 2010 and it’s working as intended. DataRow gets initialized correctly, also when switching rows with arrow keys.
Edit:
Got you now, sorry.
Looks like some async issue behind the scenes.
Maybe handling RowChanged event of the datatable itself could be a workaround for you