Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Maintain selection of the datagrdview

Posted on 2016-11-01
8
Medium Priority
?
32 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 13

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 13

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
Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

 

Author Comment

by:RIAS
ID: 41868445
I am adding rows.Columns are not touched. Need to retain rows selection
0
 
LVL 13

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 13

Accepted Solution

by:
Dustin Saunders earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

705 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