Solved

datagridview question

Posted on 2006-11-01
4
666 Views
Last Modified: 2012-08-13
Suppose I have a datagridview with hundreds of row.
How can I programatically select a cell (that is out of the display region) and make it visible and center it in the display region?
0
Comment
Question by:michellechan57
4 Comments
 
LVL 10

Expert Comment

by:anv
ID: 17855601
Can you elaborate it a bit more?
0
 

Author Comment

by:michellechan57
ID: 17855961
Thanks.
This is a windows form develop using VS2005.
The datagridview is bounded and let say it has hundreds of record.
The screen can only show the first 20 initially.
After a search operation, I wanted to display a record that is not in the first 20 (let say the record found is the 100th).
I want to be able to "move" this 100th record to the center of the screen and be visible to the user.
0
 
LVL 11

Accepted Solution

by:
anyoneis earned 500 total points
ID: 17856014
How about setting FirstDisplayedCell?

From docs:

The following code example illustrates how to ensure that the current cell is visible after sorting. This code works only with an unbound DataGridView control. With a DataGridView control bound to an external data source, the current cell is not automatically persisted when sorting.

To run this example, paste the following code into a form that contains a DataGridView named dataGridView1. In C#, you must also connect the Sorted event to the event handler.

Visual Basic  Copy Code
Private Sub dataGridView1_Sorted(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles dataGridView1.Sorted

    Me.dataGridView1.FirstDisplayedCell = Me.dataGridView1.CurrentCell

End Sub

 
C#  Copy Code
private void dataGridView1_Sorted(object sender, EventArgs e)
{
    this.dataGridView1.FirstDisplayedCell = this.dataGridView1.CurrentCell;
}

 
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17856146
hi

try this:


foreach(DataGridItem item in yourDataGrid.Items)  
{
       //Search for your record
       //if(this is the record)
       // {
       //            do somthing (you can use item.Cells[row index] to see info
       //             at specified cell)
       //}
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

23 Experts available now in Live!

Get 1:1 Help Now