I'm using a C# wrapper of ITable object (ESRI ArcObject Table), but this wrapper misses sorting and searching functions. Is there a way to add these functions? How could I do it?
1 Answers
I can think of two ways to attempt this. Both require that you create a new class that is derived from TableWrapper
.
1. The first option is to simply expose the Items
property of TableWrapper (inherited from BindingList<IRow>
). Once you have done that, you can use System.Linq
to get a sorted version of the items, or search the items. This might not work for your scenario, if you need to listen for the ListChanged event.
public class GeoGeekTable : TableWrapper
{
public IList<IRow> GetTableItems()
{
return this.Items;
}
}
2. The longer route is to provide a more complete implementation of BindingList<T>
by creating a class that inherits from TableWrapper
and implements the inherited methods that are missing in TableWrapper
.
BindingList<T>
defines these methods:
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/
}
}
I hope that helps get you started. If you search "override ApplySortCore c#" you should get some guidance on implementing that method, as it's standard .NET

- 1,858
- 1
- 21
- 27
-
Thanks for your Response, i would prefere the second way that's already implemented in wrapper that i mentioned in the link, but what i want is to avoid the NotSupportedException, because both sort and search are not supported in ITable, i thought to add these functions to the wrapper, how i could do it if possible ? Thanks – geogeek Jul 25 '12 at 19:25
-
If you have the source code for the wrapper you could alter it and add the overrides, but I think it's better to extend a class if it's part of an external library. Instead of deriving a class from ITable, derive it from TableWrapper. – mafue Jul 25 '12 at 19:38