Results 1 to 26 of 26

Thread: Little ComboBox trouble

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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

  2. #2
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    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.

  3. #3
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Little ComboBox trouble

    Welcome to the forums

    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
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    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.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    Re: Little ComboBox trouble

    The meaning is..

    1) Count

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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?

  9. #9
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    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
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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?

  11. #11

  12. #12
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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

  13. #13

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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

  14. #14

  15. #15

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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)

  16. #16

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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

  17. #17
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Little ComboBox trouble

    Juan, Post what code you have so far and I will see if I can help.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  18. #18
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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.

  19. #19
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Little ComboBox trouble

    Take a look at this quick example and see if this helps.
    Attached Files Attached Files
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  20. #20
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    499

    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.
    Attached Files Attached Files

  21. #21

  22. #22

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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!

  23. #23

    Thread Starter
    New Member
    Join Date
    Nov 2007
    Posts
    10

    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?

  24. #24

  25. #25
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Little ComboBox trouble

    Don't use VbCrLf. This is legacy vb6. Use Environment.NewLine instead as this is the actual .NET command.

  26. #26
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    499

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width