Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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?

Posted
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...

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...

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...