C# :DataGridView重新绑定时保持上次滚动位置
2009-12-08 16:09
323 查看
DataGridView虽然有VerticalScrollBar属性, 但却是受保护的对象, 无法外部访问, 看了一下DataGridView的各项属性, 发现FirstDisplayedScrollingRowIndex就是滚动条的Value, DataGridView的行高乘以FirstDisplayedScrollingRowIndex就是客户区高度.
以下是有关垂直滚动条的示例:
int _ScrollValue = 0;
private void dgvVehicles_Scroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
_ScrollValue = e.NewValue;
}
}
private void BindData()
{
// 设置数据源
...
if (dgvVehicles.Rows.Count > _ScrollValue)
dgvVehicles.FirstDisplayedScrollingRowIndex = _ScrollValue;
}
另有一种做法是设置CurrentCell, 设置该值会使DataGridView跳到该单元格所在行. 方法就是遍历各行找出那个具有唯一性的Cell, 设为当前单元格.
以下是有关垂直滚动条的示例:
int _ScrollValue = 0;
private void dgvVehicles_Scroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
_ScrollValue = e.NewValue;
}
}
private void BindData()
{
// 设置数据源
...
if (dgvVehicles.Rows.Count > _ScrollValue)
dgvVehicles.FirstDisplayedScrollingRowIndex = _ScrollValue;
}
另有一种做法是设置CurrentCell, 设置该值会使DataGridView跳到该单元格所在行. 方法就是遍历各行找出那个具有唯一性的Cell, 设为当前单元格.
相关文章推荐
- 【技巧】DataGridView,ListView重新绑定时保持上次滚动位置
- DataGridView重新绑定时保持上次滚动位置
- 【技巧】DataGridView重新绑定时保持上次滚动位置(SamWang)
- C# DataGridView重新绑定时保持上次滚动位置
- C# DataGridView重新绑定时保持上次滚动位置
- c#Winform修改datatable的列的操作和一些combox绑定实体类,dataGridview的注意点 弹出确认框 弹出的winform出现的位置 load
- C#中,datagridview与sql数据源绑定后,通过控件更改数据如何自动回写更新到数据源
- Scroll Page 表单提交后页面重新滚回原来滚动条所在位置
- 刷新后保持页面滚动条位置C#&VB
- RecyclerView重新得到焦点返回上次失去焦点的位置
- //C#查询所有DataGridView绑定
- C#语言 select语句查询结果放入经绑定数据的Datagridview控件中
- 滚动条滚动,广告保持位置不变
- ASP.NET小技巧——回传后保持页面的滚动位置
- vue-router如何在返回时返回到上次滚动位置 方法集锦
- C#中的DataGridView控件(WIN FORM),数据绑定与数据联动
- C# datagridviewcomboxcolumn数据的绑定与值的显示
- C#模糊查询绑定datagridview
- 如何做到在页面POSTBACK刷新后,使LISTBOX的滚动条仍然保持上次的位置
- C# 设置ListView某一行在刷新时始终保持可见,不随滚动条的滚动而被屏蔽