简体   繁体   中英

Datagridview event not firing

I have a dataGridView and I am trying to fire an event when a cell is clicked.I have tried using the following events with no avail:

    private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
    { 
     //dosomething
    }

    private void dataGridView2_CellMouseClick(object sender, DataGridViewCellEventArgs e)
    { 
     //dosomething 
    }

    private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
    { 
     //dosomething 
    }

    private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
    { 
     //dosomething 
    }

    private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
    { 
     //dosomething 
    }


I made sure the dataGridView 's name matched, but none of these events are firing or showing up in the debugger. Am I missing something?

Select the grid in designer, goto properties, click events button in the properties and double click on the value cell on the right of CellClick event OR Goto designer.cs file and look where all properties of gridview are defined and see if any line like this is present

gridview.CellClick += new EventHandler(dataGridView2_CellClick);

If it isnt present then add it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM