Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Visual Basic .NET (http://www.programmingforums.org/forum19.html)
-   -   Selecting A Row Across 5 Listbox's (http://www.programmingforums.org/showthread.php?t=1352)

masanovic Nov 30th, 2004 5:30 AM

Hi, what I would like to do is select a row across 5 listbox's that I have in order to delete it. I know how to select one entry in a listbox and delete that using:

If listbox1.SelectedIndex <> -1 Then
listbox1.Items.RemoveAt(listbox1.SelectedIndex)
End If

I need it now to recognise what the index of the selected item is and then select the same index number in all listbox's so that the row is highlighted. Then I can delete it.

Any help would be appreciated greatly

Infinite Recursion Nov 30th, 2004 9:22 AM

Could you assign the index of your first list box into an integer and then loop through your other list boxes and remove the same element at that position? Or will the values be in different positions in each list?

masanovic Nov 30th, 2004 9:28 AM

lol, yeh thats exactly what I have done. I used a variable as an integer and I can now select each item in the row 1 by 1 and delete it. My only problem is as soon I select one of the items in the row, I need all that row to highlight. Not have to select each item in turn.

I don't know what the code is to select (highlight) something in a listbox. I have been playing about with 'Select' but can't get anything to happen.

If you or anyone knows then please put me out of my misery.

Ooble Nov 30th, 2004 12:46 PM

I did know... In VB6, I think you just had to change the ListIndex. Not sure about .NET though.

Xyler Dec 13th, 2004 1:47 AM

What I did was create a listitem or something like that and assigned it to the item at index X. Where list.item(X) is the item you want. You then add this item to the selectedItems. Simple as that. Will go home and check the exact code for you if you need. Otherwise that is basically what you do.

bunker Dec 16th, 2004 5:07 AM

private sub listBox_selectedIndexChanged(sender as Object, evt as blahblah) handles listBox1.selectedIndexChanged, listBox2.selectedIndexChanged...

me.SelectIndeces(ctype(sender, ListBox).SelectedIndex)

end sub

private sub SelectIndeces(index as Integer)
listBox2.selectedIndex = idx
listBox3.selectedIndex = idx
...
end sub

easy, isn't it


All times are GMT -5. The time now is 4:27 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC