Results 1 to 9 of 9

Thread: [RESOLVED] combo box problem

  1. #1

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Resolved [RESOLVED] combo box problem

    hi
    i am trying to get some values from database to combo box
    and for example my resultset is rs
    and i want to put one of the resultset value in combo box
    like

    combo1.text=rs(0)

    but what happens is when this statement is executing the execution shifting to
    Private Sub combo1_Click() function

    what is the problem?

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: combo box problem

    Setting the .Text property doesn't add an item to the list, or select an item that's in the list.

    VB Code:
    1. Combo1.AddItem rs(0) & ""

  3. #3

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: combo box problem

    i don't want to add the value to the combo box.
    i just want to show the value in combo box

  4. #4

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: combo box problem

    any suggestions please??

  5. #5
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    547

    Re: combo box problem

    to "show" and item in a combobox, it has to be a value of the combobox. In other words, you need to "add" it to your combo box...

    That's the way they are designed.


    -Matthew-

  6. #6
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: combo box problem

    VB Code:
    1. combo1.Text = rs.Fields(0).Value
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: combo box problem

    Sorry, i forgot about this thread.

    As I previously said, setting the Text does not select a particular item, you need to set the ListIndex. The most efficient way to do this is to find the Index of a particular item by using API. Setting the ListIndex will fire the click event, but you can simply use a Flag to ignore it.:

    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.                 ByVal hWnd As Long, _
    3.                 ByVal wMsg As Long, _
    4.                 ByVal wParam As Long, _
    5.                 lParam As Any) As Long
    6.  
    7. Private Const CB_FINDSTRINGEXACT = &H158
    8.  
    9. Private Sub Command1_Click()
    10.     Dim sText As String
    11.     sText = rs(0) & ""
    12.     With Combo1
    13.         .Tag = "Ignore"
    14.         .ListIndex = SendMessage(Combo1.hWnd, CB_FINDSTRINGEXACT, -1, ByVal sText)
    15.          .Tag = vbNullString
    16.     End With
    17. End Sub
    18.  
    19. Private Sub Combo1_Click()
    20.     If Combo1.Tag = "Ignore" Then Exit Sub
    21.     Debug.Print "Click"
    22. End Sub

  8. #8

    Thread Starter
    Hyperactive Member wizkid's Avatar
    Join Date
    Dec 2005
    Location
    uk
    Posts
    405

    Re: combo box problem

    thanks bushmobile,
    that's great.idea is good
    it is working
    thanks a lot

  9. #9
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: combo box problem

    Cool

    Don't forget to mark this thread resolved.

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