General discussion

  • Creator
    Topic
  • #2130442

    DataCombo

    Locked

    by setivi ·

    How can I display two data fields or columns in the dropdown portion of a datacombo?
    The listfield property seems to allow only one field.

All Comments

  • Author
    Replies
    • #3547421

      DataCombo

      by sl-campbell ·

      In reply to DataCombo

      As opposed to the MS Access DBCombo, the combo box delivered with VB6 does not automatically fill a list with more than one field. You have to do this manually.
      What I do is get the fields from the recordset that I want to show in the combo and assign them to a variable. To do this you need to create a loop on the recordset in order to get the fields for all records:

      Combo1.Clear

      Do Until rsData.EOF

      sListFld1 = rsData(“myFirstField”)
      sListFld2 = rsData((“mySecondField”)

      Combo1.AddItem sListFld1 & vbTab & vbTab & sListFld2

      Loop

      There are other ways of doing this such as using a combo in conjunction with a list box and then hooking the list box up to the combo, where the list box is not visible and when the combo box isclicked, it doesn’t drop down, but instead the list box becomes visible.

      • #3547332

        DataCombo

        by sl-campbell ·

        In reply to DataCombo

        Sorry, right after AddItem and before the Loop you need to add the following line:

        rsData.MoveNext

        And you may need to add MoveFirst after Combo1.Clear

      • #3449435

        DataCombo

        by setivi ·

        In reply to DataCombo

        answer shed some light on my difficulties. very helpful.

    • #3449434

      DataCombo

      by setivi ·

      In reply to DataCombo

      This question was closed by the author

Viewing 1 reply thread