Racking my brain on this one. I have a matching game (match something in column A to that in column B, both are listboxes). I want to include a surrender function where the user selects an item in column A, clicks surrender, and then the item in column A and the corresponding one in column B are removed from the list. I can get the one in column A to be removed from the list no problem
How can I find the listindex of the column B if there are none selected in order to have that one removed from the listbox?
The data is being pulled from a db table. I would like to be able to “search” the column B rows for the text that matches the db table row of the selected column A, but not sure how to accomplish this. I was dabbling with the RowTag method, but not sure how to get this to work, even if this is the right direction.
- It’s fairly trivial to iterate through the listItems in Listbox B and find a match to a string.
For i As integer = 0 to me.ListCount-1
if me.List(i) = myString Then
2) Another possibility is to add the correct answer to the rowTag of LB A when you build the LB. Then you just…
//me refers to LB A
while this may not apply directly to this question… remember that when deleting elements from an array (listbox etc)… go in REVERSE (if there is a remote possiblity that you will be removing more than one element)
If the Listboxes can be sorted, that second option would yield incorrect results. Also, as items are removed, they would get out of sync. Roger’s first option seems better.
If there are a tremendous number of items in the Listbox, and they are sorted, you could implement a binary search to make it faster. Otherwise, cycling through the items should be very quick.
Thank you all! Roger - The first example you have is just what I needed. Thank you