Results 1 to 6 of 6

Thread: Populate a Combo box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2003
    Posts
    308

    Question Populate a Combo box

    Note: I am currently using an “Image Combo box”; can I ask what is the advantage over the regular one? What is the difference?

    Given: A form [frm1] with an Image Combo Box [cb].
    An SQL Table with many Field [Name, Other Fields…..]

    When the user presses on the Drop Down of the Combo box I want the complete list of all Names present in the [Name] column to appear (so the user can select one).

    I already have a function [Search] which returns a recordset containing the resulting rows requested, however how do I fill the combo box? Do I have to remove the other columns from my recordset (cause right now it has more then just the [Name] column). Better way?

    I attempted to mimic the method to fill a datagrid (i.e.: dg.datasource = recordset) however this gives me no results (but no errors!).

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Posts
    187
    Not sure about image combo box, but off the top of my head, here is how I fill a normal combo box.


    Code:
    Dim lngRSCount as Long
    Dim lngLoop as Long
    
    lngRSCount = rs.RecordCount 
    
    cboFill.Clear  'clears all items in a combo box 
    For lngLoop = 1 to lngRSCount
      cboFill.AddItem rs.Fields("Name")
      rs.MoveNext
    Next lngLoop
    The only other thing to note is that you do not want to have too many items in a combo box, it drives the user nuts.

    Cheers

    Jack

  3. #3
    Lively Member
    Join Date
    May 2003
    Posts
    86
    Hi,
    I have been able to populate the combo-box. But I am finding it hard to show the 1st entry in the comboboxes as SELECTED/default values and visible on form load . How can I achieve this task.

    Like,for example ,incase of HTML or ASP ,if we write SELECTED next to the Combobox field ,it would be the one displayed when ComboBox is displayed.Is there a similar function with VB.
    Thanks

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    Singapore
    Posts
    108
    Originally posted by NewbieVB2003
    Hi,
    I have been able to populate the combo-box. But I am finding it hard to show the 1st entry in the comboboxes as SELECTED/default values and visible on form load . How can I achieve this task.

    Like,for example ,incase of HTML or ASP ,if we write SELECTED next to the Combobox field ,it would be the one displayed when ComboBox is displayed.Is there a similar function with VB.
    Thanks
    simply pass the value of the first item to a variable, then set the text of the combo box as soon as it is done with the populating.

    e.g.
    Code:
    cb1.clear
    if not rs.eof then
       firstitem = rs("name")
    else
      while not rs.eof
         cb1.additem rs("name")
       rs.movenext
       wend
    end if
    cb1.text = firstitem

  5. #5
    Lively Member
    Join Date
    May 2003
    Posts
    86
    thanks
    I figured out that using listindex ,the same task can be achieved too.

  6. #6
    Just set listindex property to 0!

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