Solved

Maintain selection of the datagrdview

Posted on 2016-11-01
8
18 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
Comment Utility
Can you just store the index in a variable on selection, then after the refresh re-select the index?
0
 

Author Comment

by:RIAS
Comment Utility
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
Comment Utility
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
Comment Utility
I am adding rows.Columns are not touched. Need to retain rows selection
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:Dustin Saunders
Comment Utility
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
Comment Utility
Store in array ?
0
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
Comment Utility
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
Comment Utility
Cheers will try that
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

8 Experts available now in Live!

Get 1:1 Help Now