1
Vote

The editing row jumps on sorted DataGrid

description

I'm using SourceGrid_4_40_src on .NET 3.5

DataGrid with "Customer" table.
The table has 2 columns: "Code" and "Name".
Sort by "Code".

C-1 chemic1
C-2 metal2
C-3 mechanic3

The editing row jumps when you:
  • Enter "C-10" at the Code column.
  • And then go right cell by pressing Tab.
C-1 chemic1
C-10
C-2 metal2
C-3 mechanic3 <-- You are here.

comments

kenji_uno wrote Jan 17, 2013 at 4:07 AM

Here is my workaround. It'll chase the new row that is relocated by sorting.
~~~~~
public class UtGTS {
    SourceGrid.DataGrid gv;
    IBoundList bdv;

    public UtGTS(SourceGrid.DataGrid gv) {
        this.gv = gv;
        this.bdv = gv.DataSource;

        if (bdv != null) {
            bdv.ListChanged += bdv_ListChanged;
        }
    }

    ~UtGTS() {
        if (bdv != null) {
            bdv.ListChanged -= bdv_ListChanged;
        }
    }

    void bdv_ListChanged(object sender, ListChangedEventArgs e) {
        BoundDataView bdv = (BoundDataView)sender;
        if (e.ListChangedType == ListChangedType.ItemMoved) {
            if (gv.Selection.ActivePosition.Row - gv.FixedRows == e.OldIndex) {
                System.Threading.SynchronizationContext.Current.Post(delegate {
                    gv.Selection.Focus(new Position(e.NewIndex + gv.FixedRows, gv.Selection.ActivePosition.Column), true);
                }, null);
            }
        }
    }
}
~~~~~

Usage:
~~~~~
{
SourceGrid.DataGrid gv;
...
new UtGTS(gv);
}
~~~~~

wrote Feb 22, 2013 at 12:09 AM