Results 1 to 5 of 5

Thread: Populate combobox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129

    Question Populate combobox

    Hi All,

    anyone got an example of poulating a combobox from a table stored in SQL server. Still moving over from vb6 and not done this yet.

    Cheers in advance

  2. #2
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    There are two ways you can do this.
    The first is to open a datatable and bind it to your combo box.
    This works fine if you are not modifying the data and you don't need to add anything other than the data you return from the server.
    The other is to use a datareader and loop through the records using the datareader.read method and add your values from the reader into the combobox manually.
    If you have added data to a combo box in VB6 or previous, it works the same way in .NET.

  3. #3
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    If you populate your combobox an item at a time (like with a datareader or such) then remember to do a combobox1.BeginUpdate() before and a combobox1.EndUpdate() after. Otherwise the control redraws itself after you add each item - and will look funky.

  4. #4
    Hyperactive Member CyberHawke's Avatar
    Join Date
    May 2004
    Location
    Washington DC
    Posts
    477
    The attached file contains a simple example that retrives data from the Northwind database and populates the combo box.
    Attached Files Attached Files

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2004
    Location
    North east UK
    Posts
    129
    Many thanks for all your help.

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