您现在的位置:首页 >> 软件开发 >> 内容

C#-获取dataGridView中行号和列号

时间:2023-12-12 23:13:44 点击:

  核心提示:你是想获取总行数?还是选中行和列的索引?获取总行数:dataGridView1.Rows.Count;获取当前选中行索引:int i = this.dataGridView1.CurrentRow.I...

你是想获取总行数?还是选中行和列的索引?
获取总行数:dataGridView1.Rows.Count;
获取当前选中行索引:int i = this.dataGridView1.CurrentRow.Index;
获取当前选中列索引:int j = this.dataGridView1.CurrentCell.ColumnIndex;



//这是用鼠标从左上到右下方式选取的情况
int cellsCount = dataGridView1.SelectedCells.Count;
int c1 = (dataGridView1.SelectedCells[cellsCount-1].ColumnIndex);
int r1 = (dataGridView1.SelectedCells[cellsCount-1].RowIndex);
int c2 = (dataGridView1.SelectedCells[0].ColumnIndex);
int r2 = (dataGridView1.SelectedCells[0].RowIndex);
Console.WriteLine("选择了:第 {0} 列第 {1} 行 -- 第 {2} 列第 {3} 行",c1,r1,c2,r2);

作者:站长 来源:网络
相关文章
  • 没有相关文章
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 陈工笔记(www.dui580.com) © 2024 版权所有 All Rights Reserved.
  • 站长:陈工 微信号:chengongbiji QQ:24498854
  • Powered by 陈工