|
-
Dec 21st, 2006, 04:55 PM
#1
Thread Starter
Junior Member
[RESOLVED] textbox capturing listbox text scenario
Bad title description probably...
I have two listboxes and one text box,basically whatever item is selected in listbox1 ,the listindex of listbox2 matches the item of listbox1...
example:
listbox1 first item is orange,listbox2 first item is apple,so if listbox1 item is selected then apple is automatically selected on listbox2...simple enough so far,but i want the textbox to capture the text of listbox2 and store it in the textboxes text property...
problem is the textbox only stores the second item of listbox2 and not the first item..now i realize from previous posts on this forum that the listbox starts with 0 ,and ends with -1
but im having problems coding an IF statement on the listbox1 click event :
Code:
Private Sub lstfruits_Click()
If lstbox1.ListIndex Then
lstbox2.ListIndex = lstbox1.listindex
txtstoredfruit.Text = lstbox2.Text
End If
End Sub
so my question is,how would I fit the 0 and -1 into this IF statement?.
edit*** nevermind i figured it out ..sorry
Last edited by tinethle; Dec 21st, 2006 at 05:10 PM.
-
Dec 21st, 2006, 05:13 PM
#2
New Member
Re: textbox capturing listbox text scenario
becuase the index of the first listbox item is 0 the if statement is equating to false.
if you try this it should work for you.
VB Code:
Private Sub lstfruits_Click()
If lstbox1.ListIndex > -1 Then
lstbox2.ListIndex = lstbox1.listindex
txtstoredfruit.Text = lstbox2.Text
End If
End Sub
-
Dec 21st, 2006, 07:04 PM
#3
Thread Starter
Junior Member
Re: textbox capturing listbox text scenario
Thanks Sorbonne
I figured it out a few seconds after I posted this topic,a rather stupid mistake on my part....
thanks for your help though
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|