为大数据数组设置选定行

问题描述 投票:0回答:1

我有大约 100000 条记录的表,并使用虚拟模式将其显示在 DataGridView 中。我实现了简单的缓存类,它存储 2 页数据(每页有 100 条记录),然后将其提供给 datagridview。但是当我插入新记录时,我需要将其设置为 datagridview 中的当前位置。有什么办法可以做到吗?

c# winforms datagridview pagination
1个回答
0
投票

将新记录添加到支持数据存储中。然后使用 FirstDisplayedScrollingRowIndex 导航到新添加的行,并使用 CurrentCell (s. CurrentRow) 设置当前行:

// first add record to backing store, then:
int rowIndex = dataGridView1.Rows.Add();
dataGridView1.FirstDisplayedScrollingRowIndex = rowIndex;
dataGridView1.CurrentCell = dataGridView1[0, rowIndex];
© www.soinside.com 2019 - 2024. All rights reserved.