C#编程-71:dataGridView获取行列坐标索引和值
【摘要】
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {  ...
- private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
- {
- //获取行列坐标索引
- //方法一:
- //int row = e.RowIndex+1;
- //int col = e.ColumnIndex+1;
- //方法二:
- //int row = dataGridView1.CurrentCell.RowIndex + 1;
- //int col = dataGridView1.CurrentCell.ColumnIndex + 1;
- //方法三:
- //int row = dataGridView1.CurrentCellAddress.Y + 1;
- int col=dataGridView1.CurrentCellAddress.X+1;
- //方法四:
- int row = dataGridView1.CurrentRow.Index + 1;
- //获取当前单元格内容
- //方法1:
- // string cell = dataGridView1.Rows[row-1].Cells[col-1].Value.ToString();
- //方式2:
- string cell = dataGridView1.CurrentCell.Value.ToString();
- MessageBox.Show("点击:"+row+"行;"+col+"列\n内容是:"+cell);
- }
文章来源: pengshiyu.blog.csdn.net,作者:彭世瑜,版权归原作者所有,如需转载,请联系作者。
原文链接:pengshiyu.blog.csdn.net/article/details/81049188
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)