spidergirl1979
New member
- Joined
- Jun 26, 2009
- Messages
- 3
- Programming Experience
- 3-5
I'm at a bit of a loss and been grappling with this for several hours now, although I'm sure the solution is simple in nature.
What I would like to do is bind a combobox to my own object which is as follows:
(I have put breakpoints and I know this object has data.)
So on my form how do I bind my combobox to this object? The code I have is below:
but it returns the following error: Cannot bind to the new display member. Parameter name: newDisplayMember
What I would like to do is bind a combobox to my own object which is as follows:
VB.NET:
Public Class Categories
Public Sub New(ByVal myConn As SqlConnection)
Dim myConnection As SqlConnection = myConn
myConnection.Open()
Dim myCommand = New SqlCommand("Select [CategoryID], [Description] from CategoryLU ORDER BY Description", myConnection)
Dim dr = myCommand.ExecuteReader
If dr.HasRows Then
While dr.Read()
Me.ID.Add(dr("CategoryID"))
Me.Description.Add(dr("Description"))
_Count += 1
End While
End If
dr.Close()
End Sub
Dim _ID As New List(Of Integer)
Public Property ID() As List(Of Integer)
Get
Return _ID
End Get
Set(ByVal value As List(Of Integer))
_ID = value
End Set
End Property
Dim _Description As New List(Of String)
Public Property Description() As List(Of String)
Get
Return _Description
End Get
Set(ByVal value As List(Of String))
_Description = value
End Set
End Property
End Class
So on my form how do I bind my combobox to this object? The code I have is below:
VB.NET:
Dim bs As New BindingSource
bs.DataSource = New Inventory.Categories(myconn)
cboCategory.DataSource = bs
cboCategory.DisplayMember = "Description"
cboCategory.ValueMember = "CategoryID"