|
|
In VB6, combo boxes used to have an ItemData property which enabled the developer to hide a value
associated with a item in the list. This has now been replaced by having objects as Items in the
combo box. Although it may seem daft but it does have its advantages. First design and build the
class that is to form the Item in the combo box. Remember to include the ToString function so
the combo box knows what value to display on screen. Example class is below :-
Public Class clsDataItem
Private mid as integer
Private mvalue as string
Public Sub New ( byval id as integer, byval value as string )
mid = id
mvalue = value
end sub
Public ReadOnly Property ID() as integer
Get
return mid
End Get
End Property
Public ReadOnly Property Value() as string
Get
return mvalue
End Get
End Property
Public Overrides Function ToString() as string
return value
End Function
End Class
To implement the class in the program, all you would do is to put a combo on the form then
use the following code to add.
Combo1.Add(New clsDataItem(1,"First"))
To access the selected value, you would use the following code.
dim objDI as clsDataItem
objDI = combo1.SelectedItem()
Make a comment*Comments are the views of individuals, they may or may not be correct. All comments are reviewed and accepted or rejected. If you give an email address, you will be sent an email when someone makes a comment on this page.* | Only name and Code is compulsory. |
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
|