DataGridView : selected-record changes after sorting ???

C

cc

Hi,

using the DataGridView (.NET 2005) :
I have a row currently selected in the Grid (say the 3rd row showing
'Product3')

Now, when I click on a column to sort the records is the 'Product3' row
located as first row in the Grid but not selected (highlighted) anymore.
The position of the selected (highlighted)-row doesn't change and is still
located on the 3rd row, thus showing a dfifferent product. I don't want
this.

When sorting the records do I want to preserve the selection on the same
record not on the same row.

How can I solve this ?

thnx
Chris
 
M

Mitchell S. Honnert

Chris, I too have noticed this issue with the DataGridView. Windows
Explorer "remembers" the selected items after a sort, so it would seem
logical that the DataGridView would behave in the same manner. One can
argue whether this rises to the level of a bug, but I believe in the least
it's a design flaw. In any case...

I think the only way to get around this is to do the "remembering" yourself.
As in, before the sort, store all of the selected items, then after the
sort, reselect these items. Maybe someone else can suggest a more elegent
solution whick takes advantage of the native abilities of the DataGridView,
but when I ran into this issue, this solution was what came to mind.

- Mitchell S. Honnert
 

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