Tuesday, 11 December 2007

solution for combo box and listbox value and text

define a class for value and text strings and use them to get the information

example as below:


Dim sValue As String
Dim sText As String

Dim mli As MyListBoxItem = CType(cboMonth.SelectedItem, MyListBoxItem)
sText=mli.ToString 'or sText=cboMonth.Text
svalue=mli.Value.ToString()


If cboMonth.Text = "" Then
MsgBox("please select a month")
Exit Sub
Else
sMonth = mli.ToString
End If


Class MyListBoxItem

Protected m_text As String
Protected m_value As Integer

Public Sub New(ByVal Text As String)
m_text = Text
m_value = 0
End Sub

Public Sub New(ByVal Text As String, ByVal Value As Integer)
m_text = Text
m_value = Value
End Sub

Public Property Value() As Integer
Get
Return m_value
End Get
Set(ByVal Value As Integer)
m_value = Value
End Set
End Property

Public Overrides Function ToString() As String
Return m_text
End Function


End Class

No comments: