Odd datagridview behavior with bindingsource
I have a datagridview button on the grid called "delete" but rather than deleting I just mark a column bound to a field called "deleted." The bindingsource.filter = "deleted=0" and that works great. As I click the button, my code sets the associated deleted cell to "1" and the row drops off the datagridview as a result of the binding filter.
It works great until there is only one row of data and I click the "delete" button. While it behaves as if it works, when I try to update the datatable then, I get a null exception and I look back at the datagridview and it has a "new" record with no data in it that I did not create.
What the heck? Anyone know what's going on? Code follows:
Private SubDataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If e.RowIndex > -1 Then
If e.ColumnIndex = 6 Then
If MsgBox("Are you sure?", MsgBoxStyle.YesNo, "Deleting Lot") = MsgBoxResult.Yes Then
Dim keys(0) As DataColumn
keys(0) = Me.MyDataset.MyTable.recordIdColumn
Me.MyDataset.MyTable.PrimaryKey = keys
Dim row As MyApp.MyDataSet.MyTableRow = Me.MyDataSet.MyTable.Rows.Find(Me.DataGridView1.Rows(e.RowIndex).Cells("recordid").Value)
row.deleted = 1
row.syncdate = Now()
If IsPortable Then
row.syncflag = 1
End If
row.updatedby = MyApp.userRecordID
row.updateddate = Now()
Me.MyTableAdapter.Update(Me.MyDataset.MyTable)
Me.MyTableBindingSource.ResetBindings(False)
End If
End If
End If

