Visual Basic: Get a binding navigator to really delete a record from a DataTable.

Platform:Visual Basic
Task:Get a binding navigator to really delete a record from a DataTable.
Discussion:
When you delete an item from a DataTable using the BindingNavigator it somehow does not set the underlying table's RowState to RowState.Deleted. The pesky row will sometimes still appear when and where you don't want it to. To really get rid of it you need to set the BindingNavigator's DeleteItem property to (none) and then use the delete button's click event to programmatically nuke the record from the datatable.
Example:
'in this example CurrentSurveyID is the primary key value of the row i would like deleted
    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            Dim RowToDelete As DataRow = SheepMonitoringDataSet.tblSurveys.Rows.Find(CurrentSurveyID)
            RowToDelete.Delete()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
Back to Index