This is intended behavior. The reason is that SortedBindingList can be used as a data source to a DataGridView control in Windows Forms, and if it resorted instantly on adding new rows the user experience for in-place editing would be horrible - unusable actually (I tried ).
So when adding new items to the sorted list, the items aren't resorted unless you reapply the sort by calling ApplySort() again (or do some other operation to the list that does trigger a sort).
Was the unusable behaviour because it would resort an item after you edited a cell?
From: Brian Criswell [mailto:cslanet@lhotka.net]
Sent: Tuesday, July 18, 2006 3:39 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] SortedBindingList.SourceChanged (ListChangedType.ItemAdded behavior)
Okay, so I threw together a test with a DataGridView and a DataView. How does the DataView know to sort only after the user has finished editing a row and moved off of that row?
From: Brian Criswell [mailto:cslanet@lhotka.net]
Sent: Tuesday, July 18, 2006 4:59 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: SortedBindingList.SourceChanged (ListChangedType.ItemAdded behavior)
RockfordLhotka:This is the same testing technique I'm doing for the FilteredBindingList in 2.1 - and I'm finding similar oddities. Like you can't filter out a new row as it is added - and almost all new rows would get filtered out because they wouldn't meet the criteria - stuff like that.Rocky
Well the thing is, the filter itself is a pluggable component - so you can write your own custom filters for different purposes or needs. The default filter is fairly simplistic, although often useful. But I can't assume any given filter will provide specific functionality.
I think I have a pretty workable solution at the moment - it passes all my tests anyway, and it is composable with SortedBindingList, which is really cool.
Hi folks,
Having an unexpected problem with FilteredBindingList. When I add a new item to the underlying datasource it appears in the filtered view regardless of whether or not it passes the filtering criteria. You folks have any thoughts on solving this particular problem?
I know you have problems with adding items before they have properties set (so they might be filtered out before you can even edit them, etc.) but i already have all the properties set.
I have a number of filtered views on a single datasource. I add to the datasource and the new items appears in each list (instead of the one it should). I'm in a bind so I will probably have to 'plumb' an ...if(provider.Invoke(newItem, _filter).....an at the +++ lines below but would love to hear what the 'real' solution should be.
thanks
private void SourceChanged(object sender, ListChangedEventArgs e)
{
... switch (e.ListChangedType)
{
case ListChangedType.ItemAdded:
listIndex = e.NewIndex;
// add new value to index
newItem = _list[listIndex];
if (_filterBy != null)
newKey = _filterBy.GetValue(newItem);
else
newKey = newItem;
+++++ hang on - don't add until you see if it matches the filter +++++++
_filterIndex.Add(
new ListItem(newKey, listIndex));
Copyright (c) Marimer LLC