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.
Unfortunately, activation email could not send to your email. Please try again.

GridDataBoundGrid sorting on hidden column

Thread ID:

Created:

Updated:

Platform:

Replies:

59048 Apr 4,2007 12:48 AM Apr 4,2007 11:10 PM Windows Forms 5
loading
Tags: GridControl
Rob Yang
Asked On April 4, 2007 12:48 AM

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

haneefm [Syncfusion]
Replied On April 4, 2007 11:31 AM

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

Rob Yang
Replied On April 4, 2007 12:37 PM

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

haneefm [Syncfusion]
Replied On April 4, 2007 01:29 PM

Hi Rob,

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

Best regards,
Haneef

Rob Yang
Replied On April 4, 2007 11:08 PM

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

Rob Yang
Replied On April 4, 2007 11:10 PM

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

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.

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.

;