2011-03-10 7 views
0

내 응용 프로그램에 Winforms DataGridView가 있습니다.Windows Forms DataGridview에서 체크 상자 클릭 이벤트 캡처

두 개의 확인란과 데이터베이스의 다른 5 개 열이 있습니다. 이 두 개의 확인란 열은 DataGridViewCheckBoxColumn에 추가됩니다.

사용자가 두 번째 확인란을 클릭하면 해당 행에 대해 첫 번째 확인란을 선택하지 않은 경우 사용자에게 메시지를 표시해야합니다.

어떻게해야합니까? 이 시도했지만 셀 값이 null로 오는 것입니다. 내가 뭘 잘못 했니?

private void dgTest_CellClick(System.Object sender, DataGridViewCellEventArgs e) 
{ 
    DataGridViewCheckBoxCell officialCbCell = row.Cells[1] as DataGridViewCheckBoxCell; 
    DataGridViewCheckBoxCell includeCbCell = row.Cells[0] as DataGridViewCheckBoxCell; 

    if (officialCbCell != null) 
    { 
     if (officialCbCell.Value != null && (bool)officialCbCell.Value == true) 
     { 
      if (includeCbCell != null && (bool)includeCbCell.Value == false) 
      { 
       MessageBox.Show("INVALID"); 
      } 
     } 
    } 
} 

감사합니다.

+0

이 부분에 대한 의견을 보내주십시오. 고마워요. – Jimmy

답변

7

사용 시도 할 수 그리드의 이벤트를 CellValueChanged

void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) 
{ 
    if (e.ColumnIndex == 0) 
    { 
     bool isChecked = (Boolean) dataGridView1[0, e.RowIndex].FormattedValue; 

     if (isChecked) 
      dataGridView1[1, e.RowIndex].Value = true; 
    } 
} 

다음

1

CellContentClick 이벤트 및 cell.EditingCellFormattedValue 속성은 또한으로도 확인 다른 열 또는 다른 유효성 검사를 설정할 수 있습니다 확인하는 경우 셀을 클릭/해제 한 경우 유용합니다.

관련 문제