Datagridview full row selection but get single cell value

后端 未结 16 1199
傲寒
傲寒 2020-12-02 12:12

I have a datagridview that is a full row select. How would I grab the data from only a certain cell no matter what cell in the row was clicked on since it highlights the ent

16条回答
  •  臣服心动
    2020-12-02 12:54

    Just Use: dataGridView1.CurrentCell.Value.ToString()

            private void dataGridView1_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                MessageBox.Show(dataGridView1.CurrentCell.Value.ToString());
            }
    

    or

     // dataGrid1.Rows[yourRowIndex ].Cells[yourColumnIndex].Value.ToString()
    
     //Example1:yourRowIndex=dataGridView1.CurrentRow.Index (from selectedRow );
     dataGrid1.Rows[dataGridView1.CurrentRow.Index].Cells[2].Value.ToString()
    
     //Example2:yourRowIndex=3,yourColumnIndex=2 (select by programmatically )
      dataGrid1.Rows[3].Cells[2].Value.ToString()
    

提交回复
热议问题