Solved

Maintain selection of the datagrdview

Posted on 2016-11-01
8
30 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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