We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to disable auto-sort for GridDataBoundGrid

I am using GridDataBoundGrid, I expect the sort behavior like:
1. sort the column when user clicks on the column header.
2. when user changes the cell value, the column should not be sorted automatically. The user would need to click again on the column header to sort the table again.

Here's an example:
My table looks like this at start:
Aa
Bb
Cc
Dd

And I change the "Bb"-cell to "Gg" so it turns to:
Aa
Cc
Dd
Gg

What I want:
Aa
Gg
Cc
Dd

I tried SortBehavior property and SortColumn method, seems that both will hold the sort status inside grid and cause automatically resort right after the cell data changed. I guess the root cause is due to the DataView sort, since I used DataTable as the DataSource of GridDataBoundGrid.

Any solution to disable this auto-sort? It's quite urgent, really appreciate your quick answer!

3 Replies

JJ Jisha Joy Syncfusion Team March 9, 2010 06:22 AM UTC

Hi Shi,

Thank you for posting query to us.

Please refer the following forum thread that disscusses how to preserve the sorted rows and avoid the grid from further sorting.

http://www.syncfusion.com/support/forums/grid-windows/51318

Regards,
Jisha


SZ shi zhangjue March 10, 2010 02:15 AM UTC

Thanks.

The ListWrapper sample actually caches all the DataTable rows in an ArrayList. It works only when DataTable is ready before wrapping it to ListWrapper and setting to gridDataBoundGrid1.DataSource. What about updating DataTable dynamically after ListWrapper is set to gridDataBoundGrid1.DataSource?

I am thinking of adding a hidden column to avoid the auto-sort, does anyone have sample code to share for this idea? Thanks.


JJ Jisha Joy Syncfusion Team March 12, 2010 09:02 AM UTC

Hi Shi,

One thing you could do is by disabling the default sorting and handle the CellClick event in GridDataBoundGrid to handle manual sort as shown below.

this.gridDataBoundGrid1.SortBehavior = Syncfusion.Windows.Forms.Grid.GridSortBehavior.None;

this.gridDataBoundGrid1.CellClick += new GridCellClickEventHandler(gridDataBoundGrid1_CellClick);


void gridDataBoundGrid1_CellClick(object sender, GridCellClickEventArgs e)
{
if (e.RowIndex == 0 && e.ColIndex > 0)
{
int filed = this.gridDataBoundGrid1.Binder.ColIndexToField(e.ColIndex);
string name = this.gridDataBoundGrid1.Binder.InternalColumns[filed].MappingName;
string sort= dt.DefaultView.Sort.Contains(name)? (dt.DefaultView.Sort.Contains("ASC")?"DESC":""):"ASC";
if (sort.Length > 0)
dt.DefaultView.Sort = "[" + name + "] " + sort;
else
dt.DefaultView.Sort = String.Empty;
e.Cancel = true;
this.gridDataBoundGrid1.Refresh();
}
}



Refer the sample from below link.
http://www.syncfusion.com/uploads/redirect.aspx?&team=support&file=I65296-1948918315.zip

Regards,
Jisha

Loader.
Live Chat Icon For mobile
Up arrow icon