2012-11-29 129 views
4

当我将值添加到窗体上最后一个可见行下面的单元格时,可以执行自动滚动吗? 我在DataGridView中找不到任何自动滚动属性。是否唯一可能的方法来查找最后一个可见单元格的索引并更改FirstDisplayedScrollingRowIndex?在DataGridView中自动滚动

回答

5

您可以使用FirstDisplayedCell属性来显示该单元格。
既然你知道你添加了单元格的值,你可以像这样做:

dataGridView1.FirstDisplayedCell = yourCell 
+1

谢谢,它更方便。但是如何确定哪个单元在屏幕上可见,以及哪个 - 不是? – spyder

1

可以试试这个,

gv.FirstDisplayedCell = gv.Rows[gv.Rows.Count - 1].Cells[0]; 
1

这3条线真的等同于自动向下滚动

System.Int16 i_NotDisplayableRowCount = dataGridView1.RowCount - dataGridView1.DisplayedRowCount(false); // false means partial rows are not taken into acount 
if (i_NotDisplayableRowCount > 0) 
    dataGridView1.FirstDisplayedScrollingRowIndex = i_NotDisplayableRowCount;