datagrid sorting hassles

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top