Things I've had to hack

Sep 17, 2009 at 1:02 AM

First off, I mostly want to say thank you for the library!! You have no idea how much time/complexity you have saved me.

Being said, in my travels I've run across a few issues and just wanted to let you know about them in case you hadn't noticed. If my solutions seem retarted, please excuse them since I'm a VB coder and this was the first time I've ever had to go through a c# library.

First, my collections are usually instantiated on a non UI thread. The cross-thread events didnt cause a problem with most controls but I did have exceptions with the combobox. I needed a way to set my own dispatcher so I added a property to ContinuousCollection that allowed me to set the UI Thread's Dispatcher.

The second problem also has to do with comboboxes when properties change or items are added/removed from a SortingReadonlyContinuousCollection. If the item was selected at the time of the change, the RemoveItemFromOutput() function would cause the selection to be reset to nothing. This solution was a little trickier (at least for someone who has never coded in c#). I overloaded InsertItemInSortOrder and RemoveItemFromOutput with a boolean that would suppress the FireCollectionChanged call within them.OnItemChanged() now becomes:

 

void OnItemChanged(INotifyPropertyChanged sender, String PropName)
        {
            TSource item = (TSource)sender;
            int RemoveFrom = RemoveItemFromOutput(item, true);
            int InsertTo = InsertItemInSortOrder(item, true);
            if (RemoveFrom != InsertTo) { FireCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));}
            this.OnPropertyChanged(PropName);
        }

 

Changing the way events are called fixed the problem of having the combobox's selected item from being reset. But then I noticed that the DisplayMember of the property was not updating because the OnPropertyChanged event was never getting called/making it to the control. Thats where the additional parameter PropName comes in. I added ChangedPropName to the SubscriptionTree object, then updated the ItemChanged event in NotifyCollectionChangedMonitor to pass the property name in addition to the sender.

 

between those two changes, the combobox now seems to be acting as it should. If you think my changes may have broken some other functionality, please let me know.

 

Btw, thanks again for putting this project together.