Maintain selection of the datagrdview

Hello,
Is there anyway i can retain the selection of the datagrdview after refreshing it(rebinding) .
I have a column of selection but after rebinding it clears it off.

Cheers
RIASAsked:
Who is Participating?
 
Dustin SaundersDirector of OperationsCommented:
I'd probably use a list<int>.

For each row in your selection, store the primary key in the integer list and then after the refresh, call another function that selects (if exists in the new data) the primary key records you had originally selected.
0
 
Dustin SaundersDirector of OperationsCommented:
Can you just store the index in a variable on selection, then after the refresh re-select the index?
0
 
RIASAuthor Commented:
Can you just store the index in a variable on selection You mean array? But as I am rebinding more rows might get added so indexes change. I have a selection boolean column though.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Dustin SaundersDirector of OperationsCommented:
Maybe I misread, are you adding more columns each time or just rows?  Even if you added more rows, the column index would be the same unless you were changing that for some reason; but then you can just find the index that matches the column header to solve that.

Are you wanting to retain a column selection, or a row selection?
0
 
RIASAuthor Commented:
I am adding rows.Columns are not touched. Need to retain rows selection
0
 
Dustin SaundersDirector of OperationsCommented:
Does your data selection contain a identity key?  On refresh, you can get the primary identity key of the row and then store that, then use this to re-select after the refresh.
0
 
RIASAuthor Commented:
Store in array ?
0
 
RIASAuthor Commented:
Cheers will try that
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.