Obtain datasource for a GridGroupingControl row given its rowId and columnId

Hello,

I'm using a modified version of the sample 4.1.0.50\Windows\Grid.Windows\Samples\CellTypes\LinkLabelCells to add link label cell support to a GridGroupingControl in Visual Studio 2005.

When a link label cell is clicked, I get rowId and columnId of the clicked cell, by a call to PointToRowCol function. RowId range is peculiar, as it starts with 1, and include header row, so record cells start at row #2.

I would like to access the dataRow bound to that cell, without using the CurrentCell property. That is, translate a rowId and columnId into that cell's bounded dataRowView; of course, taking possible sorting into account.

What I do now is substract 2 to the rowId and use this value to index the DataTable row collection directly, but it doesn't take sorting into account; and if sorting is carried out, this method fails to get the correct row.

By the way, is there any way to prevent a column of a GropingGridControl to allow sorting?

Thank you very much.
Jose M.

1 Reply

RA Rajagopal Syncfusion Team September 8, 2007 02:11 AM UTC

Hi Jose,

Thanks for your interest in Syncfusion Products.

You can get the underlying datarowview of the clicked cell in the TableControlMouseDown event using the below code.

void gridGroupingControl1_TableControlMouseDown(object sender, GridTableControlMouseEventArgs e)
{
Point pt = new Point(e.Inner.X, e.Inner.Y);
GridTableCellStyleInfo styleInfo = e.TableControl.PointToTableCellStyle(pt);
if (styleInfo.TableCellIdentity.DisplayElement.Kind == DisplayElementKind.Record)
{
Record rec = styleInfo.TableCellIdentity.DisplayElement.GetRecord();
DataRowView drv = (DataRowView)rec.GetData();
foreach (object obj in drv.Row.ItemArray)
Console.Write(obj.ToString() + "\t");
Console.WriteLine();
}
}

To prevent a column from sorting in GridGroupingControl, use the TableControlQueryAllowSortColumn event and set e.AllowSort to false. Below is the code.

void gridGroupingControl1_TableControlQueryAllowSortColumn(object sender, GridQueryAllowSortColumnEventArgs e)
{
if (e.Column.Name == columnName)
e.AllowSort = false;
}

Let me know if you have any other questions.

Regards,
Rajagopal

Loader.
Up arrow icon