Combo/List boxes and having an Item/Value relationship without databases

Denaes

Senior Contributor
Joined
Jun 10, 2003
Messages
956
This is dead easy with a database. Just select one field to be an Item and another (normally the unique key ID in my experience, but not always) to be the ValueMember.

Is there a way to configure this relationship manually?
 
Denaes said:
This is dead easy with a database. Just select one field to be an Item and another (normally the unique key ID in my experience, but not always) to be the ValueMember.

Is there a way to configure this relationship manually?
You can make a class like...
Code:
Public Class cComboItem
Private iValue As Integer
Private sDisplay As String
Public Overrides Function ToString() As String
	Return sDisplay
End Function
Public Sub New(ByVal Value As Integer, ByVal Display As String)
	iValue = Value
	sDisplay = Display
End Sub

Public ReadOnly Property Value() As Integer
	Get
		Return iValue
	End Get
End Property
Public ReadOnly Property Display() As String
	Get
		Return sDisplay
	End Get
End Property
End Class

and then you just add to the proper combobox...
Code:
cboHands.Items.Add(New cComboItem(0, "None"))
cboHands.Items.Add(New cComboItem(1, "One"))
cboHands.Items.Add(New cComboItem(2, "Two"))
cboHands.Items.Add(New cComboItem(3, "Three"))
cboHands.DisplayMember = "Display"
cboHands.ValueMember = "Value"

HTH
/Kejpa
 
Back
Top