Discussion:
DataGridView - scrolling to a given row programatically
(too old to reply)
JezB
2005-04-22 14:45:53 UTC
Permalink
Not sure if DataGridView is part of VS 2005 or 2003, but does anyone know
how I can force a scroll to either the selected row or a specified row
number programatically ? I'm selecting a row programatically but it's not in
the visible portion of the grid.
David Lei
2005-04-26 16:54:45 UTC
Permalink
Subclass DataGrid and provide your own ScrollToRow function

public void ScrollToRow(int rowIndex)
{
if(this.DataSource != null)
{
this.GridVScrolled(this,new
ScrollEventArgs(ScrollEventType.LargeIncrement,rowIndex));
}
}

GridVScrolled is a function that listens to the vertical bar scroll event,
you can call it from your own function.

David
Post by JezB
Not sure if DataGridView is part of VS 2005 or 2003, but does anyone know
how I can force a scroll to either the selected row or a specified row
number programatically ? I'm selecting a row programatically but it's not in
the visible portion of the grid.
jon simcox
2009-06-18 02:18:39 UTC
Permalink
Even easier way - remember the last selected row (i.e. some unique data, or a row counter)
then when you re populate or whatever, simply use

SendKeys.Send("{HOME}");
then the line below the amount of times you want to scroll down a row -
SendKeys.Send("{DOWN}");


Works a treat - after a good evening of pulling my hair out


From http://www.developmentnow.com/g/30_2005_4_0_0_506734/DataGridView--scrolling-to-a-given-row-programatically.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/

Loading...