CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2000
    Location
    France
    Posts
    3

    Populate Combo Box from a recorset

    I want to populate a Combo Box from a recordset (I want to list every values of a column).
    Thanks ! :-)


  2. #2
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: Populate Combo Box from a recorset

    If your recordset is called rs and the field in the database that you want in the combo box is field1 then once you have opened the recordset
    do until rs.eof
    Combo1.Additem rs!field1
    rs.Movenext
    loop






  3. #3
    Join Date
    Jul 2000
    Location
    France
    Posts
    3

    Re: Populate Combo Box from a recorset

    Real thanks.
    There was a problem if thfield is null,to correct that you just have to make this test in the loop:
    If recordset.field <>" " then
    ......
    End If





  4. #4
    Join Date
    Feb 2000
    Posts
    440

    Re: Populate Combo Box from a recorset

    I think this chech <> "" is not apropriate.

    Take a look at the IsNull() function.


  5. #5
    Join Date
    Feb 2000
    Posts
    440

    Re: Populate Combo Box from a recorset

    Hi,

    The most straightforward way, apparently is
    to read one by one the records from the recordset and to add them to the list/combo box.
    This, however, is a little awkward approach, because with larger databases the time to load the control will be really long.

    As the smart people know that we will encounter such problems, they have made databound controls that can be linked to the recordset. They work really fast.

    You may wish to search a little about this databound controls in the MSDN.

    If you do not want to "waste" your time searching for these databound controls you can do a thing to speed up your loading process.

    Before starting the loop that fills the combo/list box one by one just make this combo/list box unvisible i.e. set its visible propery to false. This will speed up the process
    considerably.

    Regards,

    Valery Nikolov

    http://listen.to/quark



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