加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – DataGridView对EndNew的不必要调用

发布时间:2020-12-15 21:21:08 所属栏目:百科 来源:网络整理
导读:我正在使用一个名为SimpleFilteredList的类,我从这个站点获得: http://blogs.msdn.com/b/winformsue/archive/2007/12/06/filtering-code.aspx 它允许我在通过BindgingSource添加到DataGridView时对业务对象应用基本排序.它很好地服务于我的目的,但我不明白
我正在使用一个名为SimpleFilteredList的类,我从这个站点获得:

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

它允许我在通过BindgingSource添加到DataGridView时对业务对象应用基本排序.它很好地服务于我的目的,但我不明白一个方面.

每次在DataGridView中选择一个新行时,都会提示调用SimpleFilteredList类中的重写EndNew函数.当最后一行是选择的前一行时,这尤其令人讨厌,因为它强制执行排序算法.

所有列和DataGridView都将Readonly设置为True,AllowUserToAddRows和AllowUserToDeleteRows设置为False.

在DataGridView中选择新行时,如何停止调用此EndNew函数?

SimpleFilteredList类中的EndNew函数:

public override 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);
    }

解决方法

检查项目的索引,如果未指定,则忽略该调用.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读