Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top