V
V
Vindicar2015-11-03 14:48:47
.NET
Vindicar, 2015-11-03 14:48:47

Why is the ListBox not updating when the BindingList items are updated?

There is the following design:
there is a Frame class that implements INotifyPropertyChanged and sends notifications if the Progress property has changed (processing progress from 0 to 100).
There is a BindingList<Frame> collection, and there is a ListBox bound to it with OwnerDrawFixed.
There is code that subscribes to events from the BindingList<Frame> and fires a BackgroundWorker on new elements. The code wrapped in a BackgroundWorker uses BackgroundWorker.OnProgressChanged to set the new Frame.Progress value.
What behavior I expected:
1. The processing code calls BackgroundWorker.ReportProgress(x)
2. The handler for the BackgroundWorker.OnProgressChanged event changes the property of the corresponding Frame.Progress instance.
3. The Frame instance throws OnPropertyChanged, notifying the BindingList. The event is generated on the GUI thread, I checked.
4. The BindingList relays the event as ListChanged, notifying the ListBox of the change. This is the built-in functionality of BindingList.
5. ListBox initiates redrawing of the corresponding element.
Points 1-4 work fine, but with point 5 there is a hitch, and the ListBox is not redrawn.
How can this be fixed?
Now I just subscribe to BindingList.ListChanged, and pull

ListBox.Invalidate(ListBox.GetItemRectangle(e.NewIndex));
if the element changes, but it looks like a crutch.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question