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

Finding the correct record

Hello,

I need to get the correct record from a cell but offsets are making this difficult. For example:

protected void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
int rowIndex = e.Style.TableCellIdentity.RowIndex;
Record rec = this.GridGroupingControl1.Table.Records[rowIndex];
}

The above method has a fault: Rows containing column names or filterbar dropdowns etc, will add to the rowIndex.

What then is the best way to get a RowIndex from the cell? I need a method that is guaranteed to match the grid's RowIndex to the underlying DataTable's RecordIndex?

I could manually adjust the RowIndex (such as "e.Style.TableCellIdentity.RowIndex - 3") ... but then I am assuming the offset is always a fixed constant. Rather I need to find out at runtime how many rows are adding an offset and use that information to get the correct DataTable record.

Thanks,
Robert Claypool, Nashville, TN



2 Replies

MS Murali Samanthapudi June 27, 2008 04:11 PM UTC

Hi Robert,

Thank you for using our libraries.

Inside QueryCellStyleInfo, you can get the underlying record object directly from the TableCellIndentity. You do not have to find indexes and then index another collection to get the record object. Here is some code showing how you can use the TableCellIdentity to get at the underlying data.

void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
GridRecord record = e.TableCellIdentity.DisplayElement.GetRecord() as GridRecord;
if (record != null)
{
//to get the raw dataobject, ie the DataRowView from a DataTable datasource
//you can use
object data = record.GetData();
DataRowView drv = data as DataRowView;
if (drv != null)
{
//Console.WriteLine("field0={0} field1={1}", drv[0], drv[1]);
}
}
}


Please let us know if this is not the information you needed.

Regards,

Clay Burch



AD Administrator Syncfusion Team June 27, 2008 04:12 PM UTC

That is exactly what I needded. Thanks!


Loader.
Live Chat Icon For mobile
Up arrow icon