Public Class CItemList Private sName As String Private iID As Long ' Default empty constructor. Public Sub New() sName = "" iID = 0 End Sub Public Sub New(ByVal Name As String, ByVal ID As Integer) sName = Name iID = ID End Sub Public Property Name() As String Get Return sName End Get Set(ByVal sValue As String) sName = sValue End Set End Property ' This is the property that holds the extra data. Public Property ItemData() As Long Get Return iID End Get Set(ByVal iValue As Long) iID = iValue End Set End Property ' This is neccessary because the ListBox and ComboBox rely on this method when determining the text to display. Public Overrides Function ToString() As String Return sName End Function End Class ' adding name and id to listbox lst.Items.Add(New CItemList("xyz", 1)) 'to retrieve value from the combobox / listbox Dim ItemList As CItemList ItemList = lst.Items(lst.SelectedIndex) Return Convert.ToString(ItemList.ItemData)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)