日期:2014-05-18  浏览次数:20436 次

winform中的滚动条位置
偶有一个DataGrid控件,一个文本框,一个按钮。想单击按钮时定位到列表里面,当前文本框中ID的行。下面是我的代码:
InitGridStyle();//重新绑定(因为需要改变数据)
dataGrid1.Select(index);
dataGrid1.CurrentRowIndex   =   index;
但当列表控件中数据太多,出现滚动条的时候,滚动条就定位到顶端了。
郁闷中,有没有哪位高手做过的,帮帮忙啊!项目急啊!

------解决方案--------------------
这个应该不难吧。关键是要考虑你的DataGrid还有可能有分页情况。
------解决方案--------------------
必须继承DataGrid才行
public class DataGridEx:DataGrid
{
public DataGridEx()
{}

public void ScrollToRow(int row)
{
this.GridVScrolled(this, new ScrollEventArgs(ScrollEventType.LargeIncrement, row));
}

}