C#中DataGridView控件如何选中某个指定的单元格
发布日期:2021-05-10 02:27:03 浏览次数:21 分类:精选文章

本文共 2757 字,大约阅读时间需要 9 分钟。

������������DataGridView���������������������������������������������������������������������

1. ���������������������

���������DataGridView���������������������������������������������������������������������

string value = dataGridView1.Rows[i].Cells[j].Value;

���������i������������������������������j���������������������������������������������i���j���������������������0������������������������������

2. ������������������������

���������DataGridView���������������������������������������������������������������

int selectedRowCount = dataGridView1.SelectedRows.Count;

������������������������������������������������������������������������������������������������0���

3. ������������������������

������������������������������������������������������������������

int rowIndex = dataGridView1.SelectedRows.Index; // ������
int rowIndex = dataGridView1.CurrentRow.Index;

������������������������������������������������DataGridView������������������������������������������������������������������������������������������������

4. ���������������������������������

���������DataGridView���������������������������������������������������������������

object cellValue = dataGridView1.CurrentCell.Value;

���������������������������������������������������������������������DataGridView������������������������������CurrentCell���������null���

5. ������������������������

���������DataGridView������������������������������������������������������������

DataGridViewRow row = dataGridView1.SelectedRows[0];
DataRow dataRow = row.DataBinding���_main();
DataSet dataSet = new DataSet();
dataSet.CopyFrom(row);

������������������������dataSet���������������������������������������

6. ���������������������������������

int rowIndex = dataGridView1.SelectedRows.Index;
DataGridViewRow row = dataGridView1.Rows[rowIndex];
int columnIndex = 2;
object cellValue = row.Cells[columnIndex].Value;

������������������������columnIndex������������������������������������������������

7. ���������������������������������

DataGridViewRow selectedRow = dataGridView1.SelectedRows[0];
int columnIndex = 2;
object cellValue = selectedRow.Cells[columnIndex].Value;

8. ���������������������������������

DataGridViewCell currentCell = dataGridView1.CurrentCell;
string cellContent = currentCell.Value.ToString();

9. ������������������������N������������

DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
int column = 2;
string cellValue = row.Cells[column].Value.ToString();

������e.RowIndex���������������������������������������������������������������������������������������������column������

上一篇:C# datagridview修改指定行名和列名
下一篇:力扣-234题(Java)-ArrayList

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月11日 16时53分41秒