Solved

How to maintain selected row in a datagridview after reselecting data from Database?

Posted on 2008-06-11
3
233 Views
Last Modified: 2013-11-26
I am using a datagridview in c# application. After selecting one row and making some changes to it I need to reload all data from Database but the problem is that the selected row will be lost and it always go to the first row. What's the best way of retaining the prosition of selecte row after reloading the data.
0
Comment
Question by:Elham_Seif
3 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 21761671
you could store the rowNumber in session,hiddenField or viewstate
0
 
LVL 14

Accepted Solution

by:
Daniel Junges earned 250 total points
ID: 21761751

// Strore the index
int index = dataGridView1.CurrentRow.Index;
...
// Select the same index again
if(dataGridView1.Rows.Count < index + 1)
  dataGridView1.Rows[index].Selected = true;
0
 

Author Comment

by:Elham_Seif
ID: 21761827
thanks
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

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…
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 …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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