-
Little ComboBox trouble
Well, first of all Id like to say Im a newbie with VB, so this may seem like a stupid question to some of you, or maybe not. I really dont know. Anyway here I go:
I have this ComboBox that has different items on it (these items are movie titles). What I need is, that everytime I select a different movie, it has to appear the number on a Textbox.
I.e :
If I select V for Vendetta as my first movie the textbox has to show the number 1. Then If I change V for vendetta for another movie lets say Wedding Crashers the textbox has to show the number 2.
It has to happen everytime I select a different movie. . the textbox represents the number of different movies Im selecting..
I really dont know how to do this..at all!.. I need your help . please try to keep it simple cause as I already said before, Im a newbie at this :cool:
-
Re: Little ComboBox trouble
The simple way to do this is to put this in the Click event code:
Code:
textbox.text = combobox.listindex
And it will change the number in the textbox with each click.
-
Re: Little ComboBox trouble
Welcome to the forums:wave:
What I would suggest is to add a counter to your code, so each time you select a film you add 1 to the counter.
Code:
Dim ctr as integer
Private Sub Combo_Click()
'your code here
ctr = ctr + 1
'Add the total to your textbox
Text1.Text = ctr
End Sub
-
Re: Little ComboBox trouble
Quote:
Originally Posted by Campion
The simple way to do this is to put this in the Click event code:
Code:
textbox.text = combobox.listindex
And it will change the number in the textbox with each click.
I don't think this gives a total for the number of films selected which is what the op asked for.
-
Re: Little ComboBox trouble
To quote the OP:
"It has to happen everytime I select a different movie. . the textbox represents the number of different movies Im selecting.."
This could have multiple meanings:
1) Count
2) The unique number (index) of each entry.
Based on the other information that the OP supplied, I'd wager #2.
-
Re: Little ComboBox trouble
The meaning is..
1) Count
-
Re: Little ComboBox trouble
Well thanks to you, aikokid, I finally made it! ITs all good now...the thing is..I find myself with a new problem.. =(
Now I need..that ( on a different form) a textbox says the movies I selected.. If I selected wedding crashers and v for vendetta de textbox must show both of them..the textbox now represents the movies I already rented..can you help me with this please?. To me, it seems rather complicated.
PS: I know that If I name the form and then the control it will show the same as in the prebious form.
I.E .. Textbox1.
-
Re: Little ComboBox trouble
I accidentally posted it..sorry .. the last part was
I.e Textbox1.text= Form1.ComboBox1.SelectedItem
The only problem is that it only works for the movie that is actually selected (that would be the last one I chose) so It will only show one..not all the ones I chose...how do i do this?
-
Re: Little ComboBox trouble
Try this code:
Code:
Textbox1.Text = Textbox1.Text & " " & Form1.ComboBox1.SelectedItem
Or if the textbox is big enough and has the multiline property set to true try this:
Code:
Textbox1.Text = Textbox1.Text & vbcrlf & Form1.ComboBox1.SelectedItem
-
Re: Little ComboBox trouble
I havent tried that yet but IT sounds like it will work indeed.. The thing is . what IF the user selects more than 2 movies..?
If I use this
Textbox1.Text = Textbox1.Text & " " & Form1.ComboBox1.SelectedItem
Its only 2 movies right?.. Oh and . what is the value of the textbox1.text in this case?
Im using Select Case on the previous form so .. the form2.textbox1.text would be = to the Combobox.SelectedItem on the form 1 right? . thats what you mean?
-
Re: Little ComboBox trouble
If you already have movie A and movie B in the textbox and then the user selects movies C & D, do you want all 4 in the textbox or just C & D?
-
Re: Little ComboBox trouble
Code:
Dim lngIndex As Long
For lngIndex = 0 To List1.ListCount - 1
If List1.Selected(lngIndex) Then
Textbox1.Text = Textbox1.Text & List1.List(lngIndex) & vbCrLf
End If
Next
-
Re: Little ComboBox trouble
All 4 of them . . .If the user selects movie A. then the textbox must show the movie A .. and then selects a movie B then the textbox must show the movie A and B .. the same as C and D
-
Re: Little ComboBox trouble
-
Re: Little ComboBox trouble
Post 5 ?..Textbox.text = Combobox.listindex ?
I get error If I use ..Textbox1.text = Form1.Combobox2.ListIndex (Form1. because Im writing this on the form2)
-
Re: Little ComboBox trouble
Aikokid, Im asking you.
If I use this Textbox1.Text = Textbox1.Text & " " & Form1.ComboBox1.SelectedItem
Then Textbox1.text = ? .. If I use Select Case X on my previous form and everytime I select a different movie I put Form2.Textbox1.Text = X and use the code you gave me . itll show the same movie cause everytime I select a different movie the Textbox1.text on form2 will be the same as the one I already selected...crap -_-..this is getting complicated hehe
-
Re: Little ComboBox trouble
Juan, Post what code you have so far and I will see if I can help. :)
-
Re: Little ComboBox trouble
Quote:
Originally Posted by Juan Carlos
Post 5 ?..Textbox.text = Combobox.listindex ?
I get error If I use ..Textbox1.text = Form1.Combobox2.ListIndex (Form1. because Im writing this on the form2)
I'm sorry, I meant #12.
-
1 Attachment(s)
Re: Little ComboBox trouble
Take a look at this quick example and see if this helps.
-
1 Attachment(s)
Re: Little ComboBox trouble
It looks like theres crossed wires because Juan Carlos's code is .Net. I have put an example of what i think you want. Its 2005.
-
Re: Little ComboBox trouble
Juan, are you using VB.Net?
-
Re: Little ComboBox trouble
Sorry Ive been absent for a while. had some stuff to do. I have VB 2005 Express Edition.
Aikokid I couldnt open your Text project. dont know why , But I could open the other one. and it is exactly what I needed!. thanks a lot!
-
Re: Little ComboBox trouble
user name (post 20) really understood what I needed. But ..is there any other way of doing it a little..simpler maybe?
-
Re: Little ComboBox trouble
-
Re: Little ComboBox trouble
Don't use VbCrLf. This is legacy vb6. Use Environment.NewLine instead as this is the actual .NET command.
-
Re: Little ComboBox trouble
Juan, Are you having problems understanding the code because you wont get it much simpler than that for what you need, theres only 6 or 7 lines.