Hi I have a question about the combobox in vb.net.
The combobox I am using is not connected to a dataset or datasource. It is loaded manually via code using the following class:
So to load my listbox manually via code I do as follows:
combobox1.Items.Add(New ListboxExtender(rdr("Name"), rdr("DB_Key")))
Now if I want to select an existing item already loaded in the combobox I have tried:
combobox1.SelectedItem = New ListboxExtender(rdr("Name"), rdr("DB_Key"))
But this does not work like I thought it would.
Does anyone see what I am doing wrong ??
Thanks in advance for any assistance... I am stuck.
The combobox I am using is not connected to a dataset or datasource. It is loaded manually via code using the following class:
VB.NET:
Public Class ListboxExtender
Private sName As String
Private iID As Integer
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
Public Property ItemData() As Integer
Get
Return iID
End Get
Set(ByVal iValue As Integer)
iID = iValue
End Set
End Property
Public Overrides Function ToString() As String
Return sName
End Function
End Class
So to load my listbox manually via code I do as follows:
combobox1.Items.Add(New ListboxExtender(rdr("Name"), rdr("DB_Key")))
Now if I want to select an existing item already loaded in the combobox I have tried:
combobox1.SelectedItem = New ListboxExtender(rdr("Name"), rdr("DB_Key"))
But this does not work like I thought it would.
Does anyone see what I am doing wrong ??
Thanks in advance for any assistance... I am stuck.