Access to datasource row in gridGroupingControl1_QueryCellStyleInfo.

Hello. I am in gridGroupingControl1_QueryCellStyleInfo handler. How can I get datasource row, for which the cell belongs to ? Thank you.

3 Replies

AD Administrator Syncfusion Team May 14, 2004 04:41 AM UTC

You can GridRecord from the e.TableCellIdentity.DisplayElement. From the record, you can get the underlying DataRowView (or what ever object fills the rows in your IList datasource).
if(e.TableCellIdentity.DisplayElement is GridRecordRow)
{
	GridRecordRow row = e.TableCellIdentity.DisplayElement as GridRecordRow;
	if(row != null)
	{
		GridRecord record = row.ParentGroup.Records[0] as GridRecord;
		if(record != null)
		{
			DataRowView drv = record.GetData() as DataRowView;
			Console.WriteLine(e.Style.Text + " " + drv["LastMarket"].ToString() + " " + e.TableCellIdentity.ColIndex.ToString());
		}
	}
}


AD Administrator Syncfusion Team May 14, 2004 05:06 AM UTC

In this example always returned first record in datasource row.ParentGroup.Records[0]. How to get right source row index (for the specified cell)? Thank you.


AD Administrator Syncfusion Team May 14, 2004 06:00 AM UTC

Try working directly with the row instead of its parent.
if(e.TableCellIdentity.ColIndex > 0 && e.TableCellIdentity.RowIndex > 0 &&
	e.TableCellIdentity.DisplayElement is GridRecordRow
	&& e.TableCellIdentity.Column != null) //make sure a column is being requested
{
	GridRecordRow row = e.TableCellIdentity.DisplayElement as GridRecordRow;
	if(row != null)
	{
		DataRowView drv = row.GetData() as DataRowView;
		if(drv != null)
		{
			string name = e.TableCellIdentity.Column.Name;
			Console.WriteLine(e.Style.Text + " " + drv[name].ToString());
		}
	}
}

Loader.
Up arrow icon