如一个被绑定的table有1000条数据,而当前行选中的是第900条,
这时候当前行就在datagridview的下方,我希望滚动条能自动滚动,让当前行显示在正中间,
可以做得到吗?
5 个解决方案
#1
顶下,关注
#2
自己再顶
#3
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
int t = this.dataGridView1.CurrentCell.RowIndex - this.dataGridView1.DisplayedRowCount(true) / 2;
if (t < 0) t = 0;
this.dataGridView1.FirstDisplayedScrollingRowIndex = t;
}
{
int t = this.dataGridView1.CurrentCell.RowIndex - this.dataGridView1.DisplayedRowCount(true) / 2;
if (t < 0) t = 0;
this.dataGridView1.FirstDisplayedScrollingRowIndex = t;
}
#4
dataGridView1.FirstDisplayedScrollingRowIndex = 899;
#5
到正中间有点强人所难了,但是让行在datagridview的显示范围内还是可以的
只要dataGridView1.CurrentCell = dataGridView1.Rows[行号].Cells[列号];
就可以
只要dataGridView1.CurrentCell = dataGridView1.Rows[行号].Cells[列号];
就可以
#1
顶下,关注
#2
自己再顶
#3
private void dataGridView1_CurrentCellChanged(object sender, EventArgs e)
{
int t = this.dataGridView1.CurrentCell.RowIndex - this.dataGridView1.DisplayedRowCount(true) / 2;
if (t < 0) t = 0;
this.dataGridView1.FirstDisplayedScrollingRowIndex = t;
}
{
int t = this.dataGridView1.CurrentCell.RowIndex - this.dataGridView1.DisplayedRowCount(true) / 2;
if (t < 0) t = 0;
this.dataGridView1.FirstDisplayedScrollingRowIndex = t;
}
#4
dataGridView1.FirstDisplayedScrollingRowIndex = 899;
#5
到正中间有点强人所难了,但是让行在datagridview的显示范围内还是可以的
只要dataGridView1.CurrentCell = dataGridView1.Rows[行号].Cells[列号];
就可以
只要dataGridView1.CurrentCell = dataGridView1.Rows[行号].Cells[列号];
就可以