Databinding - Why Doesnt This Work?

  • Thread starter Thread starter ECathell
  • Start date Start date
E

ECathell

'------------------------------------------------------------------------------------------------
'Label Formats
'------------------------------------------------------------------------------------------------
Me.cboLabelFormat1.DataSource = mLabelFormatsCollection

Me.cboLabelFormat1.DisplayMember = "FormatName"
Me.cboLabelFormat1.DataBindings.Add(New Binding("Text", mProductCollection, "Formatname1"))


Me.cboLabelFormat2.DataSource = mLabelFormatsCollection

Me.cboLabelFormat2.DisplayMember = "FormatName"
Me.cboLabelFormat2.DataBindings.Add(New Binding("Text", mProductCollection, "Formatname2"))


The databinding works, but the controls display the same information depending on which the first bindings are bound. FormatName1 and FormatName2 can have different values, but both values come from mLabelFormatsCollection...

What am I missing?
 
Hi,
'------------------------------------------------------------------------------------------------
'Label Formats

'------------------------------------------------------------------------------------------------
Me.cboLabelFormat1.DataSource = mLabelFormatsCollection

Me.cboLabelFormat1.DisplayMember = "FormatName"
Me.cboLabelFormat1.DataBindings.Add(New Binding("Text",
mProductCollection, "Formatname1"))


Me.cboLabelFormat2.DataSource = mLabelFormatsCollection

Me.cboLabelFormat2.DisplayMember = "FormatName"
Me.cboLabelFormat2.DataBindings.Add(New Binding("Text",
mProductCollection, "Formatname2"))


The databinding works, but the controls display the same information
depending on which the first bindings are >bound. FormatName1 and
FormatName2 can have different values, but both values come from
What am I missing?

When you bind different Controls to the same DataSource then they navigate
together because they share a CurrencyManager (mantains position).

Bind each ComboBox to a different instance (copy) of the FormatCollection.

--- Or create a simple wrapper class, this way the external binding (all
that matters) uses a different instance while internally the same list is
used.

Public Class ListWrapper
Implements IListSource
Private _list As IList
Public Sub New(ByVal List As IList)
_list = List
End Sub

Public ReadOnly Property ContainsListCollection() As Boolean _
Implements System.ComponentModel.IListSource.ContainsListCollection
Get
Return False
End Get
End Property

Public Function GetList() As System.Collections.IList _
Implements System.ComponentModel.IListSource.GetList
Return _list
End Function
End Class

Then use it like :
ComboBox1.DataSource = New ListWrapper( mLabelFormatsCollection )
ComboBox2.DataSource = New ListWrapper( mLabelFormatsCollection )
....

If you use NET2.0 you could do:
ComboBox1.DataSource = New BindingSource( mLabelFormatsCollection, "" )
ComboBox2.DataSource = New BindingSource( mLabelFormatsCollection, "" )

HTH,
Greetings
 
Thanks that worked like a charm.....

Didn't think about the currency manager issue since the bindings were
different...
 
Back
Top