M
Martin
Hi all,
This is the situation...
DatagridView Control with datasource set to datatable.
I want the user to be able to delete x number of rows by selecting a row
with mouse then clicking a 'delete' button.
Then user clicks a 'Commit' button to update the database.
This is my delete row code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If Me.DataGridView1.SelectedRows.Count = 0 Then Exit Sub
Dim x As Integer = bs.Position
udt.Item(x).Delete()
End Sub
This is my commit changes code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
uta.Update(udt)
End Sub
The problem is that once I have deleted a row, the datatable and
datagridview become unsynchronized and the selected row in the datagrid
isn't the one that will be deleted from the dataset. (I hope that makes
sense)
I can keep things in sync by calling datatable.acceptchanges() after the row
deletion, but then the tableadapter.update() command doesn't write the
changes to the database.
Any helpful suggestions will be greatly appreciated. I can post the complete
(simplified) example if it will help.
Kind regards,
Martin.
This is the situation...
DatagridView Control with datasource set to datatable.
I want the user to be able to delete x number of rows by selecting a row
with mouse then clicking a 'delete' button.
Then user clicks a 'Commit' button to update the database.
This is my delete row code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If Me.DataGridView1.SelectedRows.Count = 0 Then Exit Sub
Dim x As Integer = bs.Position
udt.Item(x).Delete()
End Sub
This is my commit changes code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
uta.Update(udt)
End Sub
The problem is that once I have deleted a row, the datatable and
datagridview become unsynchronized and the selected row in the datagrid
isn't the one that will be deleted from the dataset. (I hope that makes
sense)
I can keep things in sync by calling datatable.acceptchanges() after the row
deletion, but then the tableadapter.update() command doesn't write the
changes to the database.
Any helpful suggestions will be greatly appreciated. I can post the complete
(simplified) example if it will help.
Kind regards,
Martin.