VB-Multiple Column displayed in ComboBox
Can multiple Column be displayed in the ComboBox? This is possible in Access.
If not then is there any alternative to do that?
Thanks
Web Development
Can multiple Column be displayed in the ComboBox? This is possible in Access.
If not then is there any alternative to do that?
Thanks
by donq
Yes.
1. Create a select query that deliveres what you want to display (3-4 fields). Test the query!
2. Switch to SQL View and copy ([Ctrl] + C) to the clipboard.
3. Close the query and open the Form containing the combo box in Design View.
4. Double click on the combo box to open its Properties window and locate the "Row Source" property. Paste the query from step 2 into the Row Source property ([Ctrl] + V).
5. Set the "Column Count" property to 3 or 4 to match your query.
6. Set the "Bound Column" to 1 (if that's where t is in your query)
7. Enter a "Column Width" for each column seperated by a semi-colon. (i.e., 0.9"; 1.6"; 2"; 2")
8. Set "List Rows" to 16 or more and the "List Width" to 6.4" (or whatever matches your item 7 total.
9. Verify the "Control Source" is set to the Table and Field yu are trying to populate with the combo box.
10. Save and close everything. Close the Form and reopen in in Form View - click your combo and make a selection. Walla!
Good Luck, Don Quigg
I was looking for VB code --
Anyway thanks for your reply
by peyison
The combobox control in VB does not have multiple columns like the one in Access. One option is to use a third party control that does have multiple columns.
Or, you can simulate columns in the VB combobox by putting a tab between each value. For example:
MyCombo.AddItem "Bob" & vbTab & "Smith" & vbTab & "35"
would create 3 "columns" of data in the combobox.
Some issues:
The combobox has preset tab stops at every 8 characters or so. So if your next entry was:
.additem "John" & vbTab & "Rothenburger" & vbTab & "41"
the text may not line up properly. You can modify the tab stops using API calls. Here is a good example for doing so:
http://www.thescarms.com/VBasic/listbox.asp
(remove any spaces in the URL - if any)
Also, since all the columns are really one text string, there is no "bound" column. If you want to pull a value out of the combobox, you have to retreive the full string, then use Left$(), Mid$() and InStr() (searching for vbTab) to get the value:
sString = MyCombo
sFirstName = Left$(sString,Instr(sString, vbTab)-1)
Hope this helps.
Thanks a lot. This was a very usefull tip
If you have more of these then let me know :-)
This discussion is closed to new replies.
Sort by Trending