我正在使用 C# wrapper of ITable object (ESRI ArcObject Table) ,但是这个包装器缺少排序和搜索功能。有没有办法添加这些功能?我该怎么做?
最佳答案
我可以想到两种方法来尝试这个。两者都需要您创建一个派生自 TableWrapper
的新类.
1. 第一个选项是简单地公开 Items
TableWrapper 的属性(继承自 BindingList<IRow>
)。完成后,您可以使用 System.Linq
获取项目的排序版本,或搜索项目。如果您需要监听 ListChanged 事件,这可能不适用于您的场景。
public class GeoGeekTable : TableWrapper
{
public IList<IRow> GetTableItems()
{
return this.Items;
}
}
2. 更长的路线是提供更完整的 BindingList<T>
实现通过创建一个继承自 TableWrapper
的类并实现 TableWrapper
中缺失的继承方法.
BindingList<T>
定义了这些方法:
ApplySortCore: Sorts the items if overridden in a derived class; otherwise, throws a NotSupportedException.
FindCore : Searches for the index of the item that has the specified property descriptor with the specified value, if searching is implemented in a derived class; otherwise, a NotSupportedException.
http://msdn.microsoft.com/en-us/library/ms132690.aspx
public class GeoGeekTable : TableWrapper
{
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
{
// see http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/22693b0e-8637-4734-973e-abbc72065969/
}
}
我希望这能帮助您入门。如果您搜索“override ApplySortCore c#”,您应该获得一些关于实现该方法的指导,因为它是标准的 .NET
关于c# - 将搜索和排序功能添加到数据绑定(bind)包装器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11654074/