如何以编程方式在 C# DataGridView 中设置记录指针?

我尝试过“DataGridView.Rows[DesiredRowIndex].Selected=true;”,但这不起作用。它所做的只是突出显示网格中的该行;它不会将记录指针移动到该行。

有帮助吗?

解决方案

要更改数据网格的活动行,您需要将数据网格的当前单元格属性设置为所选行上的非隐藏、非禁用、非标题单元格。你会这样做:

dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];

确保单元格符合上述标准。更多信息请参见:

http://msdn.microsoft.com/en-us/library/yc4fsbf5.aspx

其他提示

尝试设置焦点 DataGrid 第一的 。像这样的事情

dataGridView1.Focus();
dataGridView1.CurrentCell = this.dataGridView1[YourColumn,YourRow];

这对我的情况有效,希望对您也有帮助

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top