Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to autoscroll a datagrid

Status
Not open for further replies.

hilario1638

Programmer
Jan 20, 2004
5
US
i want to automatically scroll the data grid to a specific cell that is not visible on screen, how can i do this?

I've tryed to get the HScrollBar from the DataGrid.Controls enumeration and adding a value value until it gets the desired cell in the screen but it seems like the scrollbar is disconnected from the datagrid
 
Locate the row and the column index of the cell and then call Select():
int vRowIndex= ;
int vColumnIndex= ;
DataGridColumnStyle vDataGridColumnStyle;
vDataGridColumnStyle= m_DataGrid.TableStyles[0].GridColumnStyles[vColumnIndex];
m_DataGrid.BeginEdit(vDataGridColumnStyle,vRowIndex);
m_DataGrid.EndEdit(vDataGridColumnStyle,vRowIndex,true);
mDataGrid.Select(vRowIndex);
-obislavu-
 
thanks for the code obislavu, but it doesn't scrolls left or right, it just scrolls up and down, i need to scroll it left or right also. thanks anyway
 
ok, this is the real problem: i have a data grid with lots of columns. I use tab to switch columns, but when a column doesnt appear on the screen, the datagrid doesn't scrolls left, so i decided scroll it myself, that was my first post. any solution to this problem??
 
I think it can be done by implementing your own autoscroll for example :
public class AutoScrollArgs : EventArgs
{
private readonly bool HScroll ;
private readonly bool VScroll ;
...


}
public delegate void AutoScrollEventHandler(object sender, AutoScrollArgs e);

public class AutoScroll
{
public void StartScroll();
public void StopScroll();
public event AutoScrollEventHandler AS;
protected virtual void OnAlarm(AlarmEventArgs1 e)
{
if (AS != null)
{
// Invokes the delegates.
AS(this, e);
}
}
}

public class ScrollMe
{
public void DoAutoScroll(object sender, AlarmEventArgs1 e)
{
// here put your code to generate DataGrid.Scroll event
// until your cell is in the visible area
}
}
public class AutoScrollDriver
{
ScrollMe sc= new ScrollMe();
// Instantiates the event source.
AutoScroll ascroll = new AutoScroll();
// Wires the DoAutoScroll
ascroll.AutoScroll += new AutoScrollEventHandler(sc.DoAutoScroll);
}


-obislavu-
 
sorry 'bout my ignorance, but, how can i implement this on my DataGrid??
 
Hi there!

I found this very helpfull...

(5.60 How do I programmatically scroll the datagrid to a particular row?)

I´ts for VB, though, but its easy to translate to c#...

I think, you could use this for scrolling to a specific column also. I build my own class for a datagrid an it worked perfect for me...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top