datagrid scrolling...capturihng rows displayed in view of datagrid

P

Patrick

I have a datagrid on a property tab sheet. Lets say that the grid
contains 50 rows with 12 displaying on the first page. For this
example lets say the user scrolls down to record 3 and records 3-14
display. The user clicks off to another tab and comes back. They do
not select anything on the grid. I want to remember when they come
back to scroll to position 3 at the top through 14 on that page. I
know how to handle this if a record is selected on the grid but that
is not the case in this example. I was looking at the paint method to
get the rows and the scroll event but I don't know how to capture the
rows displayed in the view of the grid. Is there a proper sequence of
events to capture which rows are in view? Any overriden methods I
should be using? Thanks for your help.
 
P

Patrick

Thanks for your reply though as I had indicated, I am not selecting a
row. I want to be able to capture the top row and the bottom row when
the user scrolls. Thanks...
 
C

ClayB [Syncfusion]

Try this.

1) add a member to your form.
private VScrollBar gridVScrollBar = null;

2) In FormLoad, after the DataSource has been set on the grid, loop through
the grid's controls to save its vertical scrollbar, and subscribe to its
scroll event.

foreach(Control c in this.dataGrid1.Controls)
{
if(c is VScrollBar)
{
this.gridVScrollBar = c as VScrollBar;
break;
}
}

if(this.gridVScrollBar != null)
this.gridVScrollBar.Scroll += new
ScrollEventHandler(this.dataGrid1_Scroll);

3) In the handler you can get the limits.

private void dataGrid1_Scroll(object sender, ScrollEventArgs e)
{
if(e.Type == ScrollEventType.EndScroll)
{
Console.WriteLine("{0} to {1}",
this.gridVScrollBar.Value, this.gridVScrollBar.Value +
this.dataGrid1.VisibleRowCount -1);
}
}

==================================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Patrick said:
Thanks for your reply though as I had indicated, I am not selecting a
row. I want to be able to capture the top row and the bottom row when
the user scrolls. Thanks...




"ClayB [Syncfusion]" <[email protected]> wrote in message
Maybe the technique described in this FAQ can be used.

George Shepherd's Windows Forms FAQ contains an entry entitled:

How do I find the top-left visible cell in a datagrid?

Check it out at:
http://www.syncfusion.com/faq/winforms/search/880.asp

=============================================
Clay Burch, .NET MVP

Syncfusion, Inc.
visit http://www.syncfusion.com for .NET Essentials
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top