I am using custom classes to build my data objects instead of datasets but I have run into a problem with the databinding on a form when I have a Foriegn Key in my collection that points to another collection.
What I am trying to do is have the Combobox that is holding the Manufacturer data be selected with each change of the record.
Right now with the code below I get my records to scroll but the Combobox for the Manufacturer does not populate or change. Help!
[Product Class]
Public Class Product
Private _Products_ID As Integer
Public Property ID() As Integer
Get
Return _Products_ID
End Get
Set(ByVal Value As Integer)
_Products_ID = Value
End Set
End Property
Public Property Name() As String
Get
Return _Products_Name
End Get
Set(ByVal Value As String)
_Products_Name = Value
End Set
End Property
'Here is the FK
Public Property Manufacturer_ID() As Integer
Get
Return _Manufacturerer_ID
End Get
Set(ByVal Value As Integer)
_Manufacturerer_ID = Value
End Set
End Property
'more code here
End Class
[/Product Class]
[ProductCollection Class]
Public Class ProductCollection
Implements IList
Private pc As New ArrayList
Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer) Implements System.Collections.ICollection.CopyTo
pc.CopyTo(array, index)
End Sub
Public ReadOnly Property Count() As Integer Implements System.Collections.ICollection.Count
Get
Return pc.Count
End Get
End Property
Public ReadOnly Property IsSynchronized() As Boolean Implements System.Collections.ICollection.IsSynchronized
Get
Return pc.IsSynchronized
End Get
End Property
'more code here
[/ProductCollection Class]
[Manufacturer Class]
Public Class Manufacturer
Private _Website As String
Private _Name As String
Private _ID As Integer
Public Property ID() As Integer
Get
Return _ID
End Get
Set(ByVal Value As Integer)
_ID = Value
End Set
End Property
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
Public Property Website() As String
Get
Return _Website
End Get
Set(ByVal Value As String)
_Website = Value
End Set
End Property
End Class
[Manufacturer Class]
[Products Form]
Private Sub frmCards_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim bll As New Card_BLL
cards = bll.ListCards
cm = CType(BindingContext(cards), CurrencyManager)
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & vbCrLf & ex.StackTrace)
End Try
Call DoBinding()
End Sub
Private Sub DoBinding()
Me.TxtProducts_ID.DataBindings.Add(New Binding("Text", cards, "ID"))
Me.TxtProducts_Guid.DataBindings.Add(New Binding("Text", cards, "Guid"))
Me.TxtProducts_Name.DataBindings.Add(New Binding("Text", cards, "Name"))
Me.TxtProducts_Description.DataBindings.Add(New Binding("Text", cards, "Description"))
Me.TxtProducts_Price.DataBindings.Add(New Binding("Text", cards, "Price"))
Me.TxtManufacturer_ID.DataBindings.Add(New Binding("Text", cards, "Manufacturer_ID"))
Me.TxtSeries_ID.DataBindings.Add(New Binding("Text", cards, "Series_ID"))
Me.ChkProducts_Active.DataBindings.Add(New Binding("Text", cards, "IsActive"))
Me.TxtProducts_QtyOnhand.DataBindings.Add(New Binding("Text", cards, "QtyOnhand"))
Dim bll As New Manufacturer_BLL
Dim manus As Manufacturers = bll.ListManufacturers
Me.cmbManufacturer.DataBindings.Add(New Binding("ValueMember", manus, "ID"))
Me.cmbManufacturer.DataBindings.Add(New Binding("DisplayMember", manus, "Name"))
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
cm.Position = 0
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
cm.Position -= 1
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
cm.Position += 1
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
cm.Position = cm.Count - 1
End Sub
[Products Form]