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);
        }

 

相关文章:

  • 2022-01-14
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-23
  • 2021-10-27
  • 2022-12-23
  • 2022-03-09
  • 2021-11-07
  • 2022-12-23
相关资源
相似解决方案