I have a form showing records from parent table - "Provider" (databound
controls)
I have a checkedlistbox bound to a child table - "Site", via a junction
table -"PersonSite".
Items in the checkedlistbox are checked if records exist for current parent
record in the junction table.
I am having problems removing rows from the junction table if the user
deletes the parent record. Could someone tell me how to do this?
The following code does not work, "there is no row at position 15" is the
error i guess because i have removed a row in the middle of the for loop?
ds.Tables("PersonSite").DefaultView.RowFilter =
("Provider_GUID = '" &
ds.Tables("Provider").Rows(thisCurrencyManager.Position).Item("Provider_Guid
").ToString & "'")
ds.Tables("PersonSite").DefaultView.Sort = "PersonSiteID"
Dim y As String
For i As Integer = 0 To
ds.Tables("PersonSite").DefaultView.Count - 1
Dim s As String =
ds.Tables("PersonSite").DefaultView.Item(i).Item("PersonSiteID").ToString
'gives us the personsiteid of current record
For x As Integer = 0 To
ds.Tables("PersonSite").Rows.Count - 1
y =
ds.Tables("PersonSite").Rows(x).Item("PersonSiteID").ToString
If y = s Then
ds.Tables("PersonSite").Rows.RemoveAt(x)
End If
Next
Next
Similarly the following code causes "cannot access deleted row through row
number" error
Dim y As String
For i As Integer = 0 To
ds.Tables("PersonSite").DefaultView.Count - 1
Dim s As String =
ds.Tables("PersonSite").DefaultView.Item(i).Item("PersonSiteID").ToString
'gives us the personsiteid of current record
y =
ds.Tables("PersonSite").Rows.Find(s).Item("PersonSiteID").ToString
For x As Integer = 0 To
ds.Tables("PersonSite").Rows.Count - 1
If
ds.Tables("PersonSite").Rows(x).Item("PersonsiteID").ToString = y Then
ds.Tables("PersonSite").Rows(x).Delete()
End If
Next
Next
Any chance of a helping hand here?
--