Solved

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

Posted on 2008-06-11
3
232 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

18 Experts available now in Live!

Get 1:1 Help Now