新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

C# WinForm如何设置DataGridView选中指定行,c# formclosing

发布时间:2023-10-21 10:34:08

C# WinForm如何设置DataGridView选中指定行

要设置DataGridView选中指定行,可使用DataGridView的SelectedRows属性来实现。以下是一个示例代码:

// 假定dataGridView是一个DataGridView控件

// 选中第一行
dataGridView.Rows[0].Selected = true;

// 还是通过行索引选中指定行
int rowIndex = 3;
dataGridView.Rows[rowIndex].Selected = true;

// 还是通过行对象选中指定行
DataGridViewRow row = dataGridView.Rows[rowIndex];
row.Selected = true;

通过设置Selected属性为true,便可实现选中指定行。