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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

sort on different column than user selected

Thread ID:

Created:

Updated:

Platform:

Replies:

53520 Dec 14,2006 05:50 PM UTC Dec 18,2006 03:18 PM UTC WinForms 5
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On December 14, 2006 05:50 PM UTC

Hello,
I'm using a griddataboundgrid, version 3.2.1.0, in a Windows form. I have a need to sort the grid's contents on a different column than the user selects. For instance, say the grid has five columns. The user clicks on the column header 2, but I want the grid to really sort on column header 4. Any way I can accomplish this?

Thanks.

Administrator [Syncfusion]
Replied On December 15, 2006 05:13 AM UTC

Hi Jimmyd,

You would turn off the default sorting with the SortBehavior property. Then handle CellDoubleClick and do the sorting using Binder.Sort() method. Here is a code snippet to show this.

//turn OFF the Default sortbehavior....
this.gridDataBoundGrid1.SortBehavior = GridSortBehavior.None;
this.gridDataBoundGrid1.CellDoubleClick +=new GridCellClickEventHandler(gridDataBoundGrid1_CellDoubleClick);

private void gridDataBoundGrid1_CellDoubleClick(object sender, GridCellClickEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
int fieldIndex = grid.Binder.ColIndexToField(e.ColIndex);
if( e.ColIndex == 2)
{
fieldIndex = grid.Binder.ColIndexToField(4);
}
if( fieldIndex != -1)
{
grid.BeginUpdate();
grid.Binder.Sort(fieldIndex);
grid.EndUpdate(true);
grid.Refresh();
}
}

Please refer to the attached sample for implementation.
ChangeSortColumnbehavior.zip

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On December 15, 2006 04:35 PM UTC

Hi,

Okay, I see the method you're describing. Thanks very much for the response. I'll try this out.


Administrator [Syncfusion]
Replied On December 15, 2006 08:01 PM UTC

Hello,

This worked great - thanks for the help. I forgot to mention that I'm using VB.Net, but your code sample was easy to translate. Worked great.

Being greedy here, but if anyone knows of a way to do this, it would be helpful. Would you have any way to manage the Up and Down arrow graphic in the column that is double-clicked? (since it ends up in the target column that is actually being sorted)

Looks like I can capture the direction of the sort by something like this, but wasn't sure if I was going in the right direction.

Dim dt As New DataTable
Dim strSort as String
dt = myGridDataBoundGrid.DataSource
strSort = dt.DefaultView.Sort

Thanks again.

Administrator [Syncfusion]
Replied On December 18, 2006 04:59 AM UTC

Hi Jimmyd,

Use the SortDirection property of the IBindingList to find the sort direction of the grid. Here is a code snippet to show this.

CurrencyManager lm = this.BindingContext[this.gridDataBoundGrid1.DataSource ] as CurrencyManager;
ListSortDirection listSortDirection = GetSortDirection(lm.List);
Console.WriteLine("Current Sort Direction :" + listSortDirection );

///Here is method to get the Sort Direction.......
public ListSortDirection GetSortDirection(IList list)
{
if (list is IBindingList && ((IBindingList)list).SupportsSorting)
return ((IBindingList)list).SortDirection;
return ListSortDirection.Ascending;
}

Best Regards,
Haneef

Administrator [Syncfusion]
Replied On December 18, 2006 03:18 PM UTC

Hi Haneef,

That works great. I greatly appreciate the response. You guys rule.

jimmyd

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

;