2012-06-07 4 views
0

이것은 Microsoft 웹 사이트에서 DataGrid에 숫자 만 입력하는 기능입니다. 제대로 작동합니다.C# : DataGrid 셀 값이 숫자 인 경우 버튼 사용

첫 번째 행의 첫 번째 셀 값이 숫자 인 경우 버튼을 사용 설정 하시겠습니까 ??? 어떻게해야합니까 ??

private void dataGridView1_CellValidating(object sender, 
    DataGridViewCellValidatingEventArgs e) 
     { 
      ThermalDatGrid.Rows[e.RowIndex].ErrorText = ""; 
      int newInteger; 

      // Don't try to validate the 'new row' until finished 
      // editing since there 
      // is not any point in validating its initial value. 
      if (ThermalDatGrid.Rows[e.RowIndex].IsNewRow) { 
       return; 
      } 
      if (!int.TryParse(e.FormattedValue.ToString(), 
       out newInteger) || newInteger < 0) 
      { 
       e.Cancel = true; 
       ThermalDatGrid.Rows[e.RowIndex].ErrorText = "Only Numerical and Non Negative Values"; 
      } 
     } 

답변

2

시도 :

if (!int.TryParse(e.FormattedValue.ToString(), 
      out newInteger) || newInteger < 0) 
{ 
    e.Cancel = true; 
    ThermalDatGrid.Rows[e.RowIndex].ErrorText = "Only Numerical and Non Negative Values"; 
} 
else 
{ 
    yourButton.Enabled=true; 
} 
+0

: 그것은 메르, 작동합니다. – linguini

+0

환영합니다 ... – eyossi

관련 문제