1

I have a Datagridview which is binded to a ArcDataBinding.TableWrapper. So, I want it to be sorted when ColumnHeader is clicked. I tried to do the following on Click event:

ArcDataBinding.TableWrapper twapper = (ArcDataBinding.TableWrapper)((BindingSource)datagridview.DataSource).DataSource;
                ITableSort tsort = new TableSortClass();
                tsort.Table = (ITable)twapper.wrappedTable;
...
                string column_name = datagridview.Columns[e.ColumnIndex].Name;
                tsort.Fields = column_name;
                tsort.set_Ascending(column_name, false);
                tsort.set_CaseSensitive(column_name, true);
                tsort.Sort(null);
...
                ArcDataBinding.TableWrapper tableWrapper = new ArcDataBinding.TableWrapper((ITable)tsort);


                tableWrapper.UseCVDomains = true;
                BindingSource bindingSource1 = new BindingSource();
                bindingSource1.DataSource = tableWrapper; 
                datagridview.DataSource = bindingSource1;

                datagridview.Refresh();

But it doesn't seem to have any effect. Does anyone knows what is the problem?

0

Sovled by rebuilding tableWrapper with this function.

public static void ItableSortToITable(ITableSort tableSort, ref ArcDataBinding.TableWrapper twapper)
    {
        List<IRow> rows = new List<IRow>();
        ICursor cursor = tableSort.Rows;
        IRow row = null;
         twapper.Clear();
        while ((row = cursor.NextRow()) != null)
        {
            rows.Add(row);
            twapper.Add(row);
        }

        return;
    }

If somepony knows a better solution will be highly appriciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.