Results 1 to 11 of 11

Thread: Selecting an item in ComboBox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22

    Selecting an item in ComboBox

    How do I select the item in the ComboBox. The selected item will determine what will be inserted in ComboBox2.

  2. #2
    Lively Member
    Join Date
    Jan 2004
    Location
    traverse city
    Posts
    64
    you could use this

    Code:
    private sub command1_click
    dim item as string
    item = combo1.text
    combo2.additem string
    end sub
    let me know if thats not what you wanted
    Last edited by beowulf; Mar 11th, 2004 at 12:22 PM.

  3. #3
    Lively Member
    Join Date
    Aug 2003
    Location
    Philadelphia, Pa.
    Posts
    123
    the .ListIndex property moves to an entry

    combo1.List(x) property returns the text.

    combo1.list(combo1.listindex) returns the selected item.

  4. #4

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22
    Where should I put these codes?

    in the Combo1_Click? or Combo2_Click?

    when combo1 item is selected, it will determine the items to be added into combo2.

  6. #6
    Lively Member
    Join Date
    Jan 2004
    Location
    traverse city
    Posts
    64
    my bad the code i posted above should be this

    Code:
    private sub command1_click
    dim item as string
    item = combo1.text
    combo2.additem item
    end sub
    this code would be used with a command button but you could change it to whatever you wanted.

  7. #7
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Or :

    VB Code:
    1. Private Sub Combo1_Click()
    2.  Combo2.AddItem Combo1.List(Combo1.ListIndex)
    3. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  8. #8

  9. #9
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    VB Code:
    1. Private Sub Form_Load()
    2. Combo1.AddItem = Hello
    3. Combo1.AddItem -Goodbye
    4. End Sub
    5.  
    6. Private Sub Combo1_Click()
    7.     Select Case Combo1.Text
    8.        
    9.         Case "Hello"
    10.             MsgBox ("Hello")
    11.            
    12.         Case "Goodbye"
    13.             MsgBox ("Goodbye")
    14.            
    15.     End Select
    16. End Sub

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Originally posted by Madboy
    VB Code:
    1. Private Sub Form_Load()
    2. Combo1.AddItem = Hello
    3. Combo1.AddItem -Goodbye
    4. End Sub
    5.  
    6. Private Sub Combo1_Click()
    7.     Select Case Combo1.Text
    8.        
    9.         Case "Hello"
    10.             MsgBox ("Hello")
    11.            
    12.         Case "Goodbye"
    13.             MsgBox ("Goodbye")
    14.            
    15.     End Select
    16. End Sub
    What's with the = and - ? They aren't needed... They are wrong


    Has someone helped you? Then you can Rate their helpful post.

  11. #11
    Supreme User Madboy's Avatar
    Join Date
    Oct 2003
    Location
    England
    Posts
    3,253
    - was a mistake, and i couldnt remember the syntax off the top of my head regarding the =.

    The general Select Case code is a nice clean working example, he can remove my errors now.

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