I wrote an event to retrieve the first cell value of the clicked cell's row on CellContentClick
event in datagridview
. but the event is getting raised only when i click the third cell and not getting raised when i click the first or second cell of datagridview.
Please help me.
Try to implement the CellClick
event instead of CellContentClick
event
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
DataGridView theGrid = sender as DataGridView;
if(theGrid != null)
{
DataGridViewCell selectedCell = theGrid.SelectedCells[0];
//Do your logic here
}
}
To add to Rami's answer, you will also need to update the default generated code in your Form's Designer.cs
.
Original code:
this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
Change it to:
this.dataGridView1.*CellClick* += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With