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 original row in data after a sort

I think this is supposed to be easy. What am I doing wrong?

I have a databound grid and certain cells are colored based on data in the row. Before sorting everything is fine. After clicking a header, the data is resorted but the colors don't change because I'm not relating the new row positions to the data correctly.

Inside PrepareViewStyleInfo event I'm getting the CurrencyManager (cm) and then

DataView dv = cm.List as DataView;
int dataIndex = this.grid.Binder.RowIndexToListManagerPosition(e.RowIndex);

This always returns the same dataIndex for a given e.RowIndex no matter what the sort order is and so the dv[dataIndex].Row is always the same for the same e.rowIndex regardless of sort order. (?)

2 Replies

HA haneefm Syncfusion Team June 13, 2007 07:01 PM UTC

Hi Dave,

The RowIndexToListManagerPosition is required if you have multi-row records as in the Grid\Samples\DataBound\MultiRowRecord sample. Otherwise, you can use the simpler RowIndexToPosition method to retrieve the position. Below is a code snippet

DataView dv = cm.List as DataView;
int position = this.grid.Binder.RowIndexToPosition(e.RowIndex);
DataRow dr = dv[position].Row;

Best regards,
Haneef


DW Dave Wilkins June 13, 2007 07:07 PM UTC

Thanks. I tried that and it seems to work.

You are a star - thanks for getting back to me so quickly.

>Hi Dave,

The RowIndexToListManagerPosition is required if you have multi-row records as in the Grid\Samples\DataBound\MultiRowRecord sample. Otherwise, you can use the simpler RowIndexToPosition method to retrieve the position. Below is a code snippet

DataView dv = cm.List as DataView;
int position = this.grid.Binder.RowIndexToPosition(e.RowIndex);
DataRow dr = dv[position].Row;

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon