Class as text when adding the first value in a Combobox datasource


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
 
Ad

Advertisements

Y

Ying-Shen Yu[MSFT]

Hi Magnus,

Thanks of your post!

I had met a similiar problem, maybe there is an exception getting the
bounded property value.
You may check this by setting the "Debug"->"Exceptions" Choose the CLR
Exceptions in the dialog and change the "When the exception is thrown" to
"Break into the debugger and then run your program again.
If everything is fine , the program should run without breaking into the
debugger. If you get some excpetion, probably you are able to find the
cause.

If you still have problem on this issue, please be free to reply to this
thread and let me know more about your problem. escpectially if there is no
exception, you may send a small sample to me, I'll play with it and try to
figure out the problem.

Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top