To achieve we need
- Create Windows Application Project
- Drag DataGridView from tool box
- Drag a button to fill grid with dummy data
- Create Cell Double Click event
// Initialize number of columns
dataGridView1.ColumnCount = 3;
// named all 3 columns
dataGridView1.Columns[0].Name = "Name";
dataGridView1.Columns[1].Name = "Age";
dataGridView1.Columns[2].Name = "Salary";
// Create row and add dummy data
string[] row = new string[] {"Salman", "27", "5000"};
dataGridView1.Rows.Add(row);
row = new string[] {"Awais", "34", "9000"};
dataGridView1.Rows.Add(row);
row = new string[] {"Muzamil", "30", "6000"};
dataGridView1.Rows.Add(row);
If you run the program and click on button you have result like
Code to create event with mouse double click
Now, go to properties of Grid View and assign method to CellDoubleClick = dataGridView1_CellDoubleClick
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(e.RowIndex.ToString());
}
Again run the program you get index of row.
For video demo please see : This Video