开发者

DataGridView unwanted calls to EndNew

I am using a class called SimpleFilteredList which I got from this site:

http://blogs.msdn.com/b/winformsue/archive/2007/12/06/filtering-code.aspx

It allows me to apply basic sorting to business objects when added to a DataGridView through a BindgingSource. It has served my purposes very well, however I don't understand one aspect.

Each time a new row is selected in the DataGridView this prompts the overridden EndNew function in the SimpleFilteredList class to be called. This is particularly annoying when the last row was the previous row selected because it forces the sorting algorithm to be executed.

All the columns and the DataGridView have Readonly set to True, and AllowUserToAddRows and AllowUserToDeleteRows are set to False.

How can I stop this EndNew function being called when a new row is selected in the DataGridView?

EndNew function in SimpleFilteredList Class:

    public overri开发者_开发问答de void EndNew(int itemIndex)
    {
        // Check to see if the item is added to the end of the list,
        // and if so, re-sort the list.
        if (sortPropertyValue != null && itemIndex > 0 && itemIndex == this.Count - 1)
            ApplySortCore(this.sortPropertyValue, this.sortDirectionValue);
        base.EndNew(itemIndex);
    }


Check the index of the item and ignore the call if it's not specified.

Note In some scenarios, such as Windows Forms complex data binding, the collection may receive CancelNew or EndNew calls for items other than the newly added item. (Each item is typically a row in a data view.) Ignore these calls; cancel or commit the new item only when that item's index is specified.

http://msdn.microsoft.com/en-us/library/system.componentmodel.icanceladdnew.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜