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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to disable auto-sort for GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

93248 Mar 5,2010 07:46 AM UTC Mar 12,2010 09:02 AM UTC WinForms 3
loading
Tags: GridControl
shi zhangjue
Asked On March 5, 2010 07:46 AM UTC

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!

Jisha Joy [Syncfusion]
Replied On 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

shi zhangjue
Replied On 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.

Jisha Joy [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;