2011-10-03 5 views
3

datagridviewCellContentClick 이벤트의 클릭 한 셀의 행의 첫 번째 셀 값을 가져 오는 이벤트를 작성했습니다. 하지만 이벤트는 내가 세 번째 셀을 클릭하고 datagridview의 첫 번째 또는 두 번째 셀을 클릭 할 때 발생하지 않는 경우에만 발생합니다.
도와주세요.Datagridview 셀 콘텐츠 클릭 이벤트가 제대로 작동하지 않습니다.

+0

는 몇 가지 관련 코드를하시기 바랍니다 붙여 – Waqas

답변

7

가 라미의 대답에 추가하려면 CellContentClick 이벤트

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 
    } 
} 
1

대신 CellClick 이벤트를 구현하는 시도, 당신은 또한 기본 코드를 생성 업데이트해야합니다 귀하의 양식의 Designer.cs.

원래 코드 :에

this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick); 

변경을 :

this.dataGridView1.*CellClick* += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick); 
관련 문제