У меня есть DataGridView, который получен из datatable. Я пытаюсь остановить ввод пользователем нечисловых или отрицательных целых чисел или удвоений в разные столбцы из datagridview.Проверка DataGridView в C# win form
Я понимаю, что метод CellValidating обычно используется, но я не могу заставить его отображать отрицательные значения.
private void datagridview1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
string headerText = datagridview1.Columns[e.ColumnIndex].HeaderText;
// Abort validation if cell is not in the Age column.
if (!headerText.Equals("Quantity")) return;
int output;
// Confirm that the cell is an integer.
if (!int.TryParse(e.FormattedValue.ToString(), out output))
{
MessageBox.Show("Quantity must be numeric");
e.Cancel = true;
}
else if (output <= 0)
{
MessageBox.Show("Quantity must not be negative");
e.Cancel = true;
}
}
С приведенным выше кодом я все еще могу получить отрицательные или даже нулевые значения в ячейках количества.
Помощь очень ценится Спасибо
Это может решить проблему ... http://stackoverflow.com/a/4743070/1928632 – SiD