Solved

datagridview question

Posted on 2006-11-01
4
672 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

860 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