Reputation: 23
I am working with an own extended System.Windows.Forms.Datagrid
... problem is that when rows are appended, the control does not scroll bottom correctly.
Here is the snippet I use:
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);
}
This code makes the scrollbar run bottom, but content keeps on top.... Any idea on how to make it well? Already tried to .performLayout()
and .Refresh()
, got same results.
Hope you guys could help me
Upvotes: 2
Views: 112
Reputation: 125197
To set the current row of a System.WindowsForms.DataGrid
and scroll to the row you can use CurrentRowIndex
property:
datGrid1.CurrentRowIndex = 50;
For example to scroll to the last row:
datGrid1.CurrentRowIndex = d.BindingContext[datGrid1.DataSource].Count - 1;
CurrentCell
If you set the CurrentCell
of DataGridView
it selects the specified cell and scrolls to make the cell visible.
For example to select the last row and scroll to it:
dataGridView1.CurrentCell = dataGridView1.Rows[this.dataGridView1.RowCount - 1].Cells[0];
FirstDisplayedScrollingRowIndex
You can also set FirstDisplayedScrollingRowIndex
to scroll to a specific row, but it doesn't select the row:
For example to only scroll to the last row:
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount-1;
Upvotes: 1