ComboBox DataBinding problem

DPrometheus

Regular
Joined
Jan 7, 2009
Messages
50
Location
The Netherlands
Heyey

I've placed a combobox on a form called SourceCBox
in the load event on this form I placed the following code:
Code:
 _images = New List(Of Projects.Sprite)

SourceCBox.DataSource = _images
SourceCBox.ValueMember = "Filename"
SourceCBox.DisplayMember = "Name"

Dim img As New Projects.Sprite("TestImage")
img.Filename = "image.png"
_images.Add(_img)

where filename and name correspond to the properties of the Sprite object

however if I add sprites to the _image collection, the combobox never updates.
If I put a breakpoint on the DropDown event I can see in my watch that the DataSource recognizes the newly added sprite and thus corresponds with the right collection. However no items are displayed in the dropdown 'panel' of the combobox.

Anyone has a clue what I'm missing here?

~DP
 
I've made a small modification and seperated this problem to a different project.

If I use bindingSource the values are updated, however each entry in the combobox presents a different char / letter from the string. I.E. my testcase object gets initialized and sets its filename property to testimage.png
I add 2 testcase objects to my list and the values in my combobox shows this:
t
e
s
t
i
m
... etc.

Code:
        _lists = New List(Of TestCase)
        Dim tests(3) As TestCase
        For i As Integer = 0 To 3
            tests(i) = New TestCase()
        Next
        _lists.AddRange(tests)
        Dim bind As New BindingSource(_lists, "Filename")
        ComboBox1.DataSource = bind
        bind.EndEdit()

Suggestions?

~DP

Edit:
Solved this one.

What I did was set the binding back to post #1
Code:
SourceCBox.DataSource = _images
SourceCBox.ValueMember = "Filename"
SourceCBox.DisplayMember = "Name"
' Add this line
SourceCBox.BindingContext = New BindingContext()

add INotifyPropertyChanged to the sprite class

and changed the list collection to a bindinglist collection
Code:
        _lists = New BindingList(Of _images)
        _lists.AllowEdit = True
        _lists.AllowRemove = True
        _lists.AllowNew = True

That's it ;)

~ DP
 
Last edited:
Back
Top