Solved

datagridview question

Posted on 2006-11-01
4
679 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

687 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