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

GridDataBoundGrid sorting on hidden column

Hi, we have a GridDataBoundGrid which is bound to a DataTable. Let's say the table contains columns A, B, C, and D. The grid only shows columns A, B, and C. When column C is changed, we would like the grid contents re-sorted on column D. What's the best way to do this ?

Thanks for any assistance !
-Rob

5 Replies

HA haneefm Syncfusion Team April 4, 2007 03:31 PM UTC

Hi Rob,

This can be achieved by handling the CurrentCellAcceptedChanges event. In that event, you can call the sort routine for the hidden column using the SortColumn method. Here is a code snippet

private void gridDataBoundGrid1_CurrentCellAcceptedChanges(object sender, CancelEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
if( grid.CurrentCell.ColIndex == grid.Binder.NameToColIndex("C") )
{
int ColIndex = grid.Binder.NameToColIndex("D");
grid.BeginUpdate();
grid.SortColumn(ColIndex);
grid.EndUpdate(true);
grid.Refresh();
}
}

Best Regards,
Haneef


RY Rob Yang April 4, 2007 04:37 PM UTC

Thanks Haneef, but this doesn't seem to work : ColIndex is set to -1 after the call to grid.Binder.NameToColIndex("D"). I believe this is because column D is not shown in the grid (it's a column in the data table, but not in the grid). Is there another way to do this ?

-Rob

>Hi Rob,

This can be achieved by handling the CurrentCellAcceptedChanges event. In that event, you can call the sort routine for the hidden column using the SortColumn method. Here is a code snippet

private void gridDataBoundGrid1_CurrentCellAcceptedChanges(object sender, CancelEventArgs e)
{
GridDataBoundGrid grid = sender as GridDataBoundGrid;
if( grid.CurrentCell.ColIndex == grid.Binder.NameToColIndex("C") )
{
int ColIndex = grid.Binder.NameToColIndex("D");
grid.BeginUpdate();
grid.SortColumn(ColIndex);
grid.EndUpdate(true);
grid.Refresh();
}
}

Best Regards,
Haneef


HA haneefm Syncfusion Team April 4, 2007 05:29 PM UTC

Hi Rob,

Please try the attached sample and let me know if this helps.
GDBGHiddenSort.zip

Best regards,
Haneef


RY Rob Yang April 5, 2007 03:08 AM UTC

Hi Haneef - thanks for the sample. It seems to work within the sample, but still no go for us.

There is another difference between what we are doing and the sample however - we're using typed data tables. The attached code is similar to your sample, but uses typed data tables. Line 72 of Form1.cs (the colIndex > -1 test) is basically the problem we are having.

I'm not sure what we're doing wrong. Thanks for any assistance !
-Rob

>Hi Rob,

Please try the attached sample and let me know if this helps.
GDBGHiddenSort.zip

Best regards,
Haneef

GDBGHiddenSort.zip


RY Rob Yang April 5, 2007 03:10 AM UTC

Sorry, I just realized that the file I uploaded has the same name as yours. Here's another copy with a different name, to eliminate confusion.

GDBGHiddenSort2.zip

Loader.
Live Chat Icon For mobile
Up arrow icon