M
MB
Hello!
I have a form where the user add items in a database.
On this form I have a combobox with these items in it with the databaseID and the name of the item from a class.
When a new item has been added to the database, the combobox should be refreshed with the new items.
Everything works well except when adding the first item. When doing this the text shown in my combobox is the datasource class name (myapp.lstcls) instead of the displaymember.
Below I also attach the combobox refresh routine and the datasource class
Regards Magnus
''''''''''''''''''''''''''''''''''''''''''''''''
Dim lst As New ArrayList
Private Sub LoadCombo()
If cn.State <> ConnectionState.Open Then cn.Open()
Dim cmd As New SqlClient.SqlCommand("select name,tableid from Prospects_UserTables join sysobjects on id=tableid order by name", cn)
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader
lst = Nothing
lst = New ArrayList
While dr.Read
lst.Add(New lstcls(dr("name"), dr("tableid")))
End While
dr.Close()
ComboBox1.ValueMember = "IntID"
ComboBox1.DisplayMember = "StrName"
ComboBox1.DataSource = lst
End Sub
Public Class lstcls
Dim sName As String
Dim iID As Integer
Sub New(ByVal SetName As String, ByVal SetID As Integer)
sName = SetName : iID = SetID
End Sub
Public Property StrName()
Get
Return sName
End Get
Set(ByVal Value)
End Set
End Property
Public Property IntID()
Get
Return iID
End Get
Set(ByVal Value)
End Set
End Property
End Class
I have a form where the user add items in a database.
On this form I have a combobox with these items in it with the databaseID and the name of the item from a class.
When a new item has been added to the database, the combobox should be refreshed with the new items.
Everything works well except when adding the first item. When doing this the text shown in my combobox is the datasource class name (myapp.lstcls) instead of the displaymember.
Below I also attach the combobox refresh routine and the datasource class
Regards Magnus
''''''''''''''''''''''''''''''''''''''''''''''''
Dim lst As New ArrayList
Private Sub LoadCombo()
If cn.State <> ConnectionState.Open Then cn.Open()
Dim cmd As New SqlClient.SqlCommand("select name,tableid from Prospects_UserTables join sysobjects on id=tableid order by name", cn)
Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader
lst = Nothing
lst = New ArrayList
While dr.Read
lst.Add(New lstcls(dr("name"), dr("tableid")))
End While
dr.Close()
ComboBox1.ValueMember = "IntID"
ComboBox1.DisplayMember = "StrName"
ComboBox1.DataSource = lst
End Sub
Public Class lstcls
Dim sName As String
Dim iID As Integer
Sub New(ByVal SetName As String, ByVal SetID As Integer)
sName = SetName : iID = SetID
End Sub
Public Property StrName()
Get
Return sName
End Get
Set(ByVal Value)
End Set
End Property
Public Property IntID()
Get
Return iID
End Get
Set(ByVal Value)
End Set
End Property
End Class