获取DatagridViw单元格内容

在DatagridViw事件下双击CellClick事件;

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
//获取行列索引
int row = dataGridView1.CurrentCell.RowIndex + 1;
int col = dataGridView1.CurrentCell.ColumnIndex + 1;
//获取单元格内容
string cell = dataGridView1.CurrentCell.Value.ToString();
MessageBox.Show("你点击的是第" + row.ToString() + "行,第" + col.ToString() + "列\n内容为:"+cell);
}

 

猜你喜欢

转载自www.cnblogs.com/zhongruanzikong/p/11818668.html