Click to See Complete Forum and Search --> : ListBox values
Stu Bailey
October 24th, 2001, 09:50 AM
I am using the me.lstbox.selected(x) = true to scroll up and down a listbox. This seems to alter the selected row, but does not actually seem to select the row (like it would if you clicked on it).
The problems I am having is that I need to get the value of the row that the selection has moved to, has anybody got any ideas?
Cheers
Stu
Iouri
October 24th, 2001, 10:24 AM
Try
if List1.Selected(index) = True then
msgbox List1.Text
end if
Iouri Boutchkine
iouri@hotsheet.com
Boumxyz2
October 24th, 2001, 10:26 AM
msgbox Listbox.ItemData(listbox.ItemsSelected.Item(0))
0 is for the first element selected if you enabled multiselection then you'll have to loop. Sample loop is
for counter = 0 to (listbox.ItemsSelected.Count -1 )
msgbox listbox.itemdata(listbox.itemsselected.item(counter))
next
Boumxyz2
October 24th, 2001, 10:34 AM
Disregard my previous message, it works on Access.. On VB 6 use this
msgbox List1.ItemData (List1.Selected(0))
for Counter = 0 to list1.Selcount -1
msgbox list1.ItemData(List1.Selected(counter))
next
Nic
michi
October 24th, 2001, 10:37 AM
Instead of using :
lstbox.selected(x)= true
Try this:
lstbox.ListIndex=x
Regards,
Michi
Boumxyz2
October 24th, 2001, 10:40 AM
Disregard both last messages I thought that it was working nevermind.
John G Duffy
October 24th, 2001, 12:12 PM
I apparently do not understand the problem. I tried this sample progra below without any problems. When I select a list item in the listbox, It is viewable and highlighted. When I display it it comes out OK
Place a Listbox, 2 command buttons and a textbox on a form. Paste this code.
Enter a number in textbox and click Button1
Item is displayed highlighted in listbox
click button2. Item is displayed correctly
private Sub Command1_Click()
List1.Selected(Text1.Text) = true
End Sub
private Sub Command2_Click()
MsgBox List1.List(List1.ListIndex)
End Sub
private Sub Form_Load()
Dim X
for X = 0 to 100
List1.AddItem X
next X
End Sub
John G
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.