这是 Microsoft 网站上仅在数据网格中输入数字的功能,它工作正常。
如果第一行的第一个单元格值是数字,我想启用按钮???我怎样才能做到这一点??
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";
}
}