Linux 拨号vps windows公众号手机端

c#中datagridview怎么获取选中行

lewis 9年前 (2017-01-01) 阅读数 7 #程序编程
文章标签 c#

要获取DataGridView中的选中行,可以通过以下步骤来实现:

  1. 使用DataGridView的SelectedRows属性来获取选中的行的集合。
  2. 使用DataGridView的SelectedCells属性来获取选中的单元格的集合,从而获取选中的行。
  3. 使用DataGridView的CurrentRow属性来获取当前选中的行。

下面是示例代码:

// 获取选中的行
DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];

// 获取选中的行的某一列的值
string cellValue = selectedRow.Cells["ColumnName"].Value.ToString();

// 获取当前选中的行
DataGridViewRow currentRow = dataGridView1.CurrentRow;

// 获取当前选中的行的某一列的值
string currentCellValue = currentRow.Cells["ColumnName"].Value.ToString();

通过以上代码,就可以获取DataGridView中的选中行和选中行的某一列的值。

版权声明

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

发表评论:

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

热门