CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2000
    Posts
    7

    how to bound combobox ?

    hello,

    i am having difficulties in bounding a field to a combo box. i use ado to connect to the database and get what i want into a recordset.
    then i set the recordset as the record source of the combo box but all i get in return is that it displays only the first record.

    can someone help me to populate this combo box ?


  2. #2
    Join Date
    Jan 2000
    Location
    MO, USA
    Posts
    1,506

    Re: how to bound combobox ?

    I haven't been able to bind a combo box to a recordset and have the combo box populate, I always have to do it manually. Ie...


    Function FillComboBox(cboMain as ComboBox, rs as ADODB.Recordset, sFieldName as string) as Boolean
    on error Goto ErrorHandler

    While Not rs.EOF
    cboMain.AddItem rs(sFieldName)
    rs.MoveNext
    Wend

    FillComboBox = true

    Exit Function

    ErrorHandler:
    MsgBox error
    End Function





    You can call this function and just pass it your combo box contro, the recordset and the name of the field to put into the combo box and it will do it for you.

    Hope this helps,
    John

    John Pirkey
    MCSD
    www.ShallowWaterSystems.com
    John Pirkey
    MCSD (VB6)
    http://www.stlvbug.org

  3. #3
    Join Date
    Feb 2000
    Posts
    7

    Re: how to bound combobox ?

    thanks for the reply
    by the way, that's actually what i do for the moment as i can't still find out how to do it automatically


  4. #4
    Join Date
    Jan 2000
    Location
    Saskatchewan, Canada
    Posts
    595

    Re: how to bound combobox ?

    I am not sure of prior versions of vb but with vb6 there is a datacombo control, simular to the combobox, that can be bound to the database.

    d.paulson


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

Featured