R
Rick
VS 2005
I have a class of BindingList(of T) to use as a datasource for a lookup
combobox. The combobox is to lookup the Terms for a Purchase Order.
When I implement this on my Winform, the combobox does not synch with the
underlying data, i.e. the Terms description does not show for the terms
number.
The combobox does show the Descriptions in the drop-down box, so they are
being filled into the binding list, they just don't synch with the
underlying data.
Can anyone see what is wrong?
Rick
**** combox box is connected like this ***
cbTerms.DisplayMember = "Name"
cbTerms.ValueMember = "Num"
Dim bs As LookupNVP = New LookupNVP(LookupNVP.listType.Terms, fMain.conn)
cbTerms.DataSource = bs
cbTerms.DataBindings.Clear()
cbTerms.DataBindings.Add("SelectedValue", PObind, "Termsnum")
**** class for bindinglist ****
Public Class LookupNVP
Inherits BindingList(Of nvp)
Public Enum listType
Terms
Shipvia
End Enum
Public Class nvp
Private _name As String
Private _num As Integer
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
Public ReadOnly Property Num() As Integer
Get
Return _num
End Get
End Property
Private Sub New()
End Sub
Public Sub New(ByVal newValue As Integer, ByVal newName As String)
_name = newName
_num = newValue
End Sub
End Class
Public Sub New(ByVal list As listType, ByVal conn As FbConnection)
MyBase.New()
Dim sql As String
Select Case list
Case listType.Shipvia
sql = "Select SHIPVIANUM, METHOD || ' [' || SHIPVIANUM || ']' " _
& "from SHIPVIA order by METHOD"
Case listType.Terms
sql = "Select TERMSNUM, DESCRIPTION || ' [' || TERMSNUM || ']' " _
& "from TERMS order by DESCRIPTION"
End Select
If sql Is Nothing Then Return
Dim cmd As FbCommand = New FbCommand(sql, conn)
'Dim reader As FbDataReader
Try
conn.Open()
Using reader As FbDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
While reader.Read
Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1)))
End While
reader.Close()
End Using
Finally
conn.Close()
End Try
End Sub
End Class
I have a class of BindingList(of T) to use as a datasource for a lookup
combobox. The combobox is to lookup the Terms for a Purchase Order.
When I implement this on my Winform, the combobox does not synch with the
underlying data, i.e. the Terms description does not show for the terms
number.
The combobox does show the Descriptions in the drop-down box, so they are
being filled into the binding list, they just don't synch with the
underlying data.
Can anyone see what is wrong?
Rick
**** combox box is connected like this ***
cbTerms.DisplayMember = "Name"
cbTerms.ValueMember = "Num"
Dim bs As LookupNVP = New LookupNVP(LookupNVP.listType.Terms, fMain.conn)
cbTerms.DataSource = bs
cbTerms.DataBindings.Clear()
cbTerms.DataBindings.Add("SelectedValue", PObind, "Termsnum")
**** class for bindinglist ****
Public Class LookupNVP
Inherits BindingList(Of nvp)
Public Enum listType
Terms
Shipvia
End Enum
Public Class nvp
Private _name As String
Private _num As Integer
Public ReadOnly Property Name() As String
Get
Return _name
End Get
End Property
Public ReadOnly Property Num() As Integer
Get
Return _num
End Get
End Property
Private Sub New()
End Sub
Public Sub New(ByVal newValue As Integer, ByVal newName As String)
_name = newName
_num = newValue
End Sub
End Class
Public Sub New(ByVal list As listType, ByVal conn As FbConnection)
MyBase.New()
Dim sql As String
Select Case list
Case listType.Shipvia
sql = "Select SHIPVIANUM, METHOD || ' [' || SHIPVIANUM || ']' " _
& "from SHIPVIA order by METHOD"
Case listType.Terms
sql = "Select TERMSNUM, DESCRIPTION || ' [' || TERMSNUM || ']' " _
& "from TERMS order by DESCRIPTION"
End Select
If sql Is Nothing Then Return
Dim cmd As FbCommand = New FbCommand(sql, conn)
'Dim reader As FbDataReader
Try
conn.Open()
Using reader As FbDataReader =
cmd.ExecuteReader(CommandBehavior.CloseConnection)
While reader.Read
Me.Add(New nvp(reader.GetInt32(0), reader.GetString(1)))
End While
reader.Close()
End Using
Finally
conn.Close()
End Try
End Sub
End Class