开发者

Datagridview cellcontent click event not working properly

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 gettin开发者_StackOverflow中文版g 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜