Hi lasha,
Sorry pal - I went to sleep...this time gap thing is one thing that get's
into way every now and then
...I guess that's why many of the usual ppl
aren't posting....I don't even know whether you will read this post or not
AFAIK, there is no 'graceful' strightforward way of doing this...As i said
in my earlier post, the reverse method is quite simple to do. But in this
case, you need a workaround. The reason is that DataGrid.Select accepts only
an integer, and we need to figure out where in the datagrid our selected row
is currently placed. If the user changes the sort, the problem becomes all
the more significant because the position of our row will be different (as
per the sort expression).
In one of my previous projects, we had implemented a lil soluntion which
could be used here as well. The steps are as follows:
1. Programmatically add a new column to your datatable and fill in integers
starting from the first row to the last (1-n). Say, let the column name be
"myID".
2. Select the datarow you need using the select expression (DataTable.Select)
3. Find out the myID value of this row.
4. Use the datagrid.Select method to select that row passing in this integer.
5. Make sure that you handle the datagrid's sort event. When this happens,
you need to reset all the values in the myID column to the way they appear in
the grid. For this, you just access the defaultview of the datatable (which
is the sorted one) and then set the myID values with respect to that. With
this, you will be able to select rows even if the datagrid gets sorted
There might be better ways for doing this....I am still searching.
PS: If you want, I could post the code as well.
HTH,
Rakesh