Linux 拨号vps windows公众号手机端

C# WinForm怎么设置DataGridView选中指定行

lewis 8年前 (2017-12-24) 阅读数 12 #程序编程
文章标签 c#WinForm

要设置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,即可实现选中指定行。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门