Solved

datagridview question

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net mvc5 3 38
Library to convert HTML to PDF. 8 46
Converting C# Objects into JSON file 7 41
Round up to 100% in .NET 10 46
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

13 Experts available now in Live!

Get 1:1 Help Now