I have two lstboxes, one access db with two tables with a one to many relationship. lstbox1 is filled from table1(one to many relationship) and lstbx2 is filled from table2 (many in the one to many relationship).
Before the item in lstbox1 is deleted all relationships listed in lstbox2 must be deleted first. That can be an arduous task if lstbox2 has bunches of records. Therefore, it would seem that if the items in lstbox2 can be counted, then why not be able to add each item to a collection and then delete them one at a time.
For this discussion lstbox1 is lstTeam and lstbox2 is lstPlayer. Each has a separate Class, CTeam and CPlayer.
Something like this:
The For Next loop will add item highlighted in the lstbox but the second time thru tries to add it again which it can not do. Is there a way to cycle thru the lstbox and add each item to the collection which can then be put into another For Next loop to delete the players before the team is deleted from the tables?
Thank you.
Before the item in lstbox1 is deleted all relationships listed in lstbox2 must be deleted first. That can be an arduous task if lstbox2 has bunches of records. Therefore, it would seem that if the items in lstbox2 can be counted, then why not be able to add each item to a collection and then delete them one at a time.
For this discussion lstbox1 is lstTeam and lstbox2 is lstPlayer. Each has a separate Class, CTeam and CPlayer.
Something like this:
Code:
dim i as integer
dim c as new collection
dim obj as object
dim objPlayer as object
dim CT as CTeam
dim CP as CPlayer
obj = lstTeam.SelectedItem
objPlayer = lstPlayer.SelectedItem 'only works if item is highlighted
CT = CType(obj, CTeam)
CP = CType(objPlayer, CPlayer)
For i = 0 To lstBox2.Items.Count
c.Add(CP, CP.PID)
Next i
The For Next loop will add item highlighted in the lstbox but the second time thru tries to add it again which it can not do. Is there a way to cycle thru the lstbox and add each item to the collection which can then be put into another For Next loop to delete the players before the team is deleted from the tables?
Thank you.