Here's a section of the codes:
On the click of the parent's grid:
dataset.Tables("Table1").Defaultview.rowfilter = myfilter
.
.
.
Then, on the delete button:
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim aTable As DataTable = dsTASKS.Tables("table2")
If GetSelectedRows(ChildDataGrid).Count > 0 Then
Dim o As Object
For Each o In GetSelectedRows(ChildDataGrid)
Dim aRow As DataRow = aTable.Rows(CInt(o))
aRow.Delete()
Next o
Try
CType(ChildDataGrid.DataSource, DataTable).DefaultView.AllowDelete = True
daChild.Update(dataset, "table2")
dataset.AcceptChanges()
CType(ChildDataGrid.DataSource, DataTable).DefaultView.AllowDelete = False
Catch ex As SqlException
dataset.RejectChanges()
MessageBox.Show(ex.Message)
End Try
Else
MessageBox.Show("No Rows selected for Deletion.")
End If
End Sub
Public Function GetSelectedRows(ByVal dg As DataGrid) As ArrayList
Dim al As New ArrayList
Dim dv As DataView = CType(_currencyManager.List, DataView)
Dim i As Integer
While i < dv.Count
If dg.IsSelected(i) Then
al.Add(i)
End If
i = i + 1
End While
Return al
End Function
----
It would work if I did not have the rowfilter on the click of the parent's datagrid. But I need the rowfilter to show only the corresponding records in the child's datagrid.
Also, I did not allow deleting of rows by hitting the delete key after selecting rows. That's why I had the allowdelete set to False and only made it true when the button was clicked.
How can I get this to work?