datagrid sorting hassles

  • Thread starter Thread starter steven shingler
  • Start date Start date
S

steven shingler

Hi all,
I've got a datagrid.
I have a function which selects certain rows in a datagrid thus:

public void selectRows(string key, string columnName)
{
int count = 0;
foreach(DataRow dr in ((DataView)dg_aspects.DataSource).Table.Rows)
{
if(dr[columnName].ToString()==key)
dg_aspects.Select(count);
else
dg_aspects.UnSelect(count);
count++;
}
}

This works, but when the user clicks a column header to sort the
datagrid, the selected columns remain at the same index.

For example - if the top two rows are selected initially.
After sort - the top two rows are still selected, but the datagrid is
showing different results in those rows.

It appears that the DataTable the DataGrid is showing, and the
DataDource we work with aren't the same where sorting is concerned.

Does anyone know how to get a handle on the sorted DataTable?

I hope that's clear - thanks for taking a look
Steven
 
Hi Steven,

I see your problem - but the grid cannot do this for you. A workaround can
be to remember the selected rows' primary keys and when the grid is
re-sorted, unselect any selected rows and re-select the rows having the
remembered primary keys.
 
Back
Top