How to get DataGridView cell value in messagebox?

Brezhnews picture Brezhnews · Apr 6, 2011 · Viewed 158.5k times · Source

How can I get DataGridView cell value to be written in the MessageBox in C#?

Answer

Mohsen Safari picture Mohsen Safari · Nov 19, 2012
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    if (dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null)
    {
       MessageBox.Show(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());
    }
}