c# datagridview doubleclick on row with FullRowSelect

Metalhead89 picture Metalhead89 · Dec 4, 2012 · Viewed 101.2k times · Source

I have a datagridview in my C# application and the user should only be able to click on full rows. So I set the SelectionMode to FullRowSelect.

But now I want to have an Event which is fired when the user double clicks on a row. I want to have the row number in a MessageBox.

I tried the following:

 this.roomDataGridView.CellContentDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.roomDataGridView_CellCont‌ ​entDoubleClick); 

 private void roomDataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
      MessageBox.Show(e.RowIndex.ToString());
 }

Unforunately nothing happens. What am I doing wrong?

Answer

cihadakt picture cihadakt · Apr 12, 2013

In CellContentDoubleClick event fires only when double clicking on cell's content. I used this and works:

    private void dgvUserList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    {
        MessageBox.Show(e.RowIndex.ToString());
    }