Hi,
I found a way to include my items dynamically by following this how-to:
http://www.mgbrown.com/PermaLink37.asp x
If you dont want to take a look on the link here it goes:
But, what if you want to change the selected property to an ValueDescriptio nPair added value?
For example, I did:
on form load.. and then to set the selected value to the second option the .SelectedItem property receives what?
How would you know the reference to your ValueDescriptio nPair like this?
thanks
I found a way to include my items dynamically by following this how-to:
http://www.mgbrown.com/PermaLink37.asp x
If you dont want to take a look on the link here it goes:
Code:
Public Class ValueDescriptionPair
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Class used to control the comboBox components
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Usage:
'To add items to the list you use code like this:
'
'ComboBox1.Items.Add(New ValueDescriptionPair(1, "first item"))
'ComboBox1.Items.Add(New ValueDescriptionPair(2, "second item"))
'ComboBox1.Items.Add(New ValueDescriptionPair(3, "third item"))
'
'To get the value stored in Value and displays in a message box:
'Dim ItemSelected As Integer
'ItemSelected = CType(ComboBox1.SelectedItem,ValueDescriptionPair).Value
'MsgBox("Value Selected = " & ItemSelected)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private m_Value As Object
Private m_Description As String
#Region "properties"
Public ReadOnly Property Value() As Object
Get
Return m_Value
End Get
End Property
Public ReadOnly Property Description() As String
Get
Return m_Description
End Get
End Property
#End Region
Public Sub New(ByVal NewValue As Object, ByVal NewDescription As String)
m_Value = NewValue
m_Description = NewDescription
End Sub
Public Overrides Function ToString() As String
Return m_Description
End Function
End Class
For example, I did:
Code:
CmbBoxType.Items.Add(New ValueDescriptionPair(1, "Type 1")) CmbBoxType.Items.Add(New ValueDescriptionPair(2, "Type 2"))
How would you know the reference to your ValueDescriptio nPair like this?
thanks
Comment