I have set a constraint on 40 float fields in my SQL Server DB to not allow anything less than zero. What is the best way to create a constraint in a databound UI? Is there no way to add a check constraint to a strongly typed DataSet?
I can hook up the Parse event of each individual binding, but this seems cumbersome. For example, the binding already adds the feature that on entering a non numeric value in a field bound to a float, then the field can't lose focus until the value is entered correctly.
So far, I have to hook up a Parse event for every single field such as:
csharp Code:
Binding bRate = new Binding( "Text", this.statusNotesBindingSource, this.notesDataSet.StatusNotes.payRateColumn.ColumnName, true, DataSourceUpdateMode.OnValidation, String.Empty, "n2" ); bRate.Parse += new ConvertEventHandler(bRate_Parse); ... void bRate_Parse(object sender, ConvertEventArgs e) { if (e.DesiredType == typeof(Single)) { if (Convert.ToSingle(e.Value) < 0) e.Value = 0; } }
Is there a better way?


Reply With Quote