DataGridView 不需要调用 EndNew
我正在使用一个名为 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);
}
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 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查该项目的索引,如果未指定则忽略该调用。
http://msdn.microsoft.com/en-us/library /system.componentmodel.icanceladdnew.aspx
Check the index of the item and ignore the call if it's not specified.
http://msdn.microsoft.com/en-us/library/system.componentmodel.icanceladdnew.aspx