Coleby

This is my 1st C# VS proj and I'm having some difficulty validating data entered on a column.

HEre's the code.

if (dgExtents.Columns[e.ColumnIndex].Name == "Sequence") //number is currently < 300

{

dgExtents.Rows[e.RowIndex].ErrorText = "";

int newInteger;

if (dgExtents.Rows[e.RowIndex].IsNewRow) { return; }

if (!int.TryParse(e.FormattedValue.ToString(),

out newInteger) || newInteger < 0)

{

e.Cancel = true;

dgExtents.Rows[e.RowIndex].ErrorText = "the Sequence value must be a number";

}

if (string.IsNullOrEmpty(e.FormattedValue.ToString()))

{

dgExtents.Rows[e.RowIndex].ErrorText =

"Sequence is a required field";

e.Cancel = true;

}



Re: Windows Forms Data Controls and Databinding How do I allow the user to enter a negative number in a column on a grid with validation?

Friendly Dog

The condition you use specifically say negative number is not allowed:

if (!int.TryParse(e.FormattedValue.ToString(), out newInteger) || newInteger < 0)

translate into english is

"if the number format is invalid OR the number is negative"






Re: Windows Forms Data Controls and Databinding How do I allow the user to enter a negative number in a column on a grid with validation?

Coleby

thanks again FD.

Very simple.