Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataGridView中的自动滚动_C#_Winforms_Datagridview - Fatal编程技术网

C# DataGridView中的自动滚动

C# DataGridView中的自动滚动,c#,winforms,datagridview,C#,Winforms,Datagridview,当我向窗体上最后一个可见行下方的单元格添加值时,是否可以执行自动滚动? 我在DataGridView中找不到任何autoscroll属性。查找最后一个可见单元格的索引并更改FirstDisplayedScrollingRowIndex是否是唯一可行的方法?您可以使用FirstDisplayedCell属性来显示该单元格。 因为您知道向哪个单元格添加了值,所以可以这样做: dataGridView1.FirstDisplayedCell = yourCell 你可以试试这个 gv.FirstDi

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

您可以使用
FirstDisplayedCell
属性来显示该单元格。
因为您知道向哪个单元格添加了值,所以可以这样做:

dataGridView1.FirstDisplayedCell = yourCell
你可以试试这个

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

这三行实际上相当于自动向下滚动

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;

谢谢,它更方便。但是如何确定哪个单元格在屏幕上可见,哪个-否?