滚动到底部,但内容保持在顶部

Scroll goes bottom, but content keeps at top

我正在使用自己的扩展 System.Windows.Forms.Datagrid...问题是当添加行时,控件无法正确滚动到底部。

这是我使用的片段:

if (filasAInsertar.Length > 0)
{
    int row_count = niceDataGridDesvios.getVisibleRowsCount(niceDataGridDesvios.Parent) - 1;
    ExtendedDataGrid extendedDataGrid = niceDataGridDesvios.dataGrid;
    extendedDataGrid.getScrollBar().Value = extendedDataGrid.getScrollBar().Maximum;
    niceDataGridDesvios.dataGrid.selectFullRow(row_count);
}

此代码使滚动条 运行 底部,但内容保持在顶部...。知道如何让它更好吗?已经尝试 .performLayout().Refresh(),得到相同的结果。

希望大家能帮帮我

数据网格

设置a的当前行 System.WindowsForms.DataGrid and scroll to the row you can use CurrentRowIndex 属性:

datGrid1.CurrentRowIndex = 50;

例如滚动到最后一行:

datGrid1.CurrentRowIndex = d.BindingContext[datGrid1.DataSource].Count - 1;

DataGridView

CurrentCell

如果您设置 DataGridViewCurrentCell 它 select 指定的单元格并滚动以使单元格可见。

例如 select 最后一行并滚动到它:

dataGridView1.CurrentCell = dataGridView1.Rows[this.dataGridView1.RowCount - 1].Cells[0];

FirstDisplayedScrollingRowIndex

您还可以设置 FirstDisplayedScrollingRowIndex 滚动到特定行,但它不会 select 行:

例如只滚动到最后一行:

dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount-1;