Binding with a class that derives from List
How can I bind my ComboBox with a class that derives from List(Of T)? I
have tried assigning the class instance directly to ComboBox.DataSource,
which doesn't work. I have tried to assign the instance to
BindingSource.DataSource too (and then assigning that BindingSource to
ComboBox.DataSource), this one also doesn't update my ComboBox when new
items are added to/removed from the List. Only the objects that existed in
the List at the time of binding are shown.
The DisplayMember and ValueMember properties of the ComboBox are properly
set.
Here is my List class:
Public Class DrawingObjectsList
Inherits List(Of DrawingObjectBase)
...
End Class
Here is the list instance:
Private mDOs As New DrawingObjectsList
Here's my ComboBox and accompanying BindingSource binding:
Dim WithEvents bsDOs As System.Windows.Forms.BindingSource
bsDOs.DataSource = mDOs
cboObjects.DataSource = Me.bsDOs
cboObjects.DisplayMember = "Name"
cboObjects.ValueMember = "ObjectID"
No comments:
Post a Comment