Solved

Maintain selection of the datagrdview

Posted on 2016-11-01
8
24 Views
Last Modified: 2016-11-01
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
0
Comment
Question by:RIAS
  • 4
  • 4
8 Comments
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41868423
Can you just store the index in a variable on selection, then after the refresh re-select the index?
0
 

Author Comment

by:RIAS
ID: 41868427
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
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41868444
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
 

Author Comment

by:RIAS
ID: 41868445
I am adding rows.Columns are not touched. Need to retain rows selection
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41868448
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
 

Author Comment

by:RIAS
ID: 41868451
Store in array ?
0
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41868461
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
 

Author Closing Comment

by:RIAS
ID: 41868466
Cheers will try that
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now