> How do I get the correct DataTable index from a sorted DataView and a
> DataGrid.SelectedIndex?
>
> I have a sortable DataGrid on a form with a ButtonColumn.
> The DataGrid is bound to a DataView, which in turn is linked to a
> DataTable. The DataView is persisted between round trips via a
> session variable.
>
> When the ButtonColumn it is clicked, I wish to retrieve a value from
> the corresponding row in the DataTable.
> This works fine so long as the DataGrid has not been sorted.
> When it is sorted, the value retrieved is from the incorrect row.
My solution is to insert the primary key field as an invisible column into
the DataGrid. When my button column is clicked, I use the code
"e.Item.Cells[0].Text" to retrieve the selected primary key. I can then use
that to lookup the whole row in the DataTable to get all associated
information.

It would be cleaner if DataView objects could translate indexes based on
sorts and filters, but this will have to do.


Nathan