datagridview保持滚动条位置

操作数据之后,往往需要刷新DataGridView, 可是滚动的位置会回到开头。

让操作的人很不舒服。

可以用下面的代码来解决

int iScrollIndex = grdList.FirstDisplayedScrollingRowIndex;

// 往grid里加数据...

if (iScrollIndex >= 0 && iScrollIndex < grdList.RowCount)
{
grdList.FirstDisplayedScrollingRowIndex = iScrollIndex;
}

 

posted @ 2012-06-12 13:07  johnsonshu  阅读(569)  评论(0编辑  收藏  举报