Discussion Locked

Visual Basic - Combo Box

0 helpful
11 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Can 2 Values used in a Combo-Box. because I want to save only the short value in the database.

The short value should not be visible in the drop down list

e.g. USA, United States Of America
IN, India
JP, Japan
AUS, Australia
I know in Ms Access you can hide the entire coloum in the drop down list can this simillar feature be implemented in VB 6.0

11 replies

by danprem

It is not possible to store string values in such a manner. you can store long integers for each item useing the "ItemData" property.

The alternative to that is to declare a string array and use it to store the strings in the corresponding location.

by d_r_dan_c

set your range to be 2 x N columns as you suggested above.
set your ComboBox attributes as:
BoundColumn = 2, ColumnCount = 2
TextColumn = 1
set ColumnWidth to be wide enough to include the text column you need, say, 100 pt.
you should be all set

by rrv

So you are working in Database app where you want to store code and display descriptions. while fetching data obviously you'll have to use left/right inner/outer joins to bring code and descriptions. While loading combo you can use itemdata to store numeric codes. To invariably store the code first additem the description append it with space$(100) and after that the code. Now the code will not be seen by user. now while you want to get the code of the selected item use the below one line function. i have given function for both code returning and description returning for a selected item in a combo box.

Public Function GetCode(cboCtl As ComboBox) As String
GetCode = Trim(Right$(cboCtl.List(cboCtl.ListIndex), Len(cboCtl.List(cboCtl.ListIndex)) - InStr(1, cboCtl.List(cboCtl.ListIndex), Space$(100), vbTextCompare)))
End Function
Public Function GetDescription(cboCtl As ComboBox) As String
GetDescription = Trim(Left$(cboCtl.List(cboCtl.ListIndex), InStr(1, cboCtl.List(cboCtl.ListIndex), Space$(100), vbTextCompare)))
End Function

This logic works easy and no reengineering. only in VB7 you have additional functionality of combo to store the codes. I'm using this logic for last 4 years and works fine.

All the best
RV
rv_ooty@hotmail.com

by madestroitsolutions

Use a DBCombo from Microsoft.
Generally, when you work with the DataList and DataCombo controls, you use two Data controls; one to fill the list as designated by the Listfield and RowSource properties and one to update a field in a database specified by the DataSource and DataField properties.

The ListField property designates the field used to fill the list. The second Data control, as designated by the DataSource property, manages a Recordset containing a field to be updated. Once the user chooses one of the items in the list, the field specified by the BoundColumn property is passed to the field in the second Data control, as designated by the DataSource and DataField properties. This way you can designate one field to fill the list, and another field (from the same Recordset) to pass as data to the Recordset designated by the DataSource and DataField properties when an item is selected.

Hope that helps, if you need further help, drop me a line at:

Webmaster@Xgalore.com

by sl-campbell

Set a component reference to the "Microsoft Forms 2.0 Library" and use the combo box from it.

This discussion is closed to new replies.