|
-
Jun 3rd, 2003, 05:18 PM
#1
Thread Starter
Hyperactive Member
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!).
-
Jun 4th, 2003, 08:45 AM
#2
Addicted Member
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
-
Jun 11th, 2003, 02:57 PM
#3
Lively Member
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
-
Jun 11th, 2003, 08:32 PM
#4
Lively Member
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
-
Jun 11th, 2003, 09:17 PM
#5
Lively Member
thanks 
I figured out that using listindex ,the same task can be achieved too.
-
Jun 13th, 2003, 04:27 AM
#6
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|