Temporarily disable sorting flexgrid after update action

Posted by: samuel.maharjan on 29 October 2024, 6:44 am EST

  • Posted 29 October 2024, 6:44 am EST

    I’ve a winforms flexgrid with the datasource assigned to a datatable fetched from database and programmatically sorted.

    DataTable fetchedData = DatabaseCall();
    flexGrid.DataSource = fetchedData;
    
    flexGrid.GroupDescriptions = new List<GroupDescription>
            {
                new GroupDescription("TYPE", ListSortDirection.Ascending, false),
                new GroupDescription("DESCRIPTION", ListSortDirection.Ascending, false),
                new GroupDescription("KEY_TARIFF_1", ListSortDirection.Ascending, false),
                new GroupDescription("ORDER", ListSortDirection.Ascending, false)
            };

    The sorting needs to be set to multi column as the user is able to further change the sorting.

    The issue comes when I add a new row or update a cell. After the cell is edited the grid resorts itself and the current selection is lost. How can I disable the sorting only for the edit action and re-enable it afterwards?

  • Posted 30 October 2024, 3:06 am EST - Updated 30 October 2024, 3:11 am EST

    Hello,

    In bound mode, sorting is done automatically after data in DataTable changes. This is why, when any update is performed, sorting is done automatically. This is a .NET behavior, i.e., behavior is by design.

    To overcome this, you can delay the commit of edits by setting c1FlexGrid1.EditOptions to EditFlags.DelayedCommit. This causes FlexGrid to commit changes to the data source only when changing rows or moving focus. (The default value of this property is EditFlags.All, i.e., delayed commit is on by default.)

    By default, the selection in FlexGrid moves to the next row, which causes the edits to commit just after hitting the “Enter” key to finish editing a cell. To change this action, you can set the KeyActionEnter property to anything other than KeyActionEnum.MoveDown. [Now, you’ll be able to see how delayed commit works.]

    Please see the attached GIF and sample for implementation.

    Regards,

    Uttkarsh.

    Sample: FlexGrid_DisableSortingAfterEdit.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels