Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2265
IDataErrorInfo & Business Object field in TextBox
posted

I am currently using data binding in my Windows Forms application.

I am taking the View Model approach which wraps all of my business functionality together.  My data objects are Entity Framework POCOs which have all of the database metadata that includes maximum length, null etc.  Each object implements the IDataErrorInfo interface.  Entity Framework takes care of the field validation.

Now given that, I want to get the error messages into an UltraValidator.  The only info I have is from 2009 on these forums which indicated that it did not support the interface.  It would be great if it did although the IDataErrorInfo interface is not that great IMHO.

So my question is, I have lots of validation on different fields, what is the best way to do this.

So suppose I have a business object (without IDataErrorInfo and it implements INotifyPropertyChanged which is omitted):

public class MyPOCO

{

private string _name;

public string Name

{

get { return _name; }

set { _name = value; OnPropertyChanged("Name"); }

}

private int _age;

public int Age

{

get { return _age; }

set { _age = value; OnPropertyChanged("Age"); }

}

}

This is bound to a TextBox and a Numeric UpDown:

this.NameTextbox.DataBindings.Add("Text"this.ViewModel.MyPOCO, "Name", trueDataSourceUpdateMode.OnPropertyChanged );
this.Age.DataBindings.Add("Text"this.ViewModel.MyPOCO, "Age", trueDataSourceUpdateMode.OnPropertyChanged );

I want to add all kinds of validation I guess.  This will be:

  • Max Length on Name field/textbox.
  • Name Required
  • Age Required
  • Age Between 10 and 20 or Between 30 and 40

Do I need a single UltraValidator instance or do I need to add many instances?  I am currently using:

this.EntityValidator.GetValidationSettings(this.NameTextbox).EmptyValueCriteria = Infragistics.Win.Misc.EmptyValueCriteria.NullOrEmptyString;
this.EntityValidator.GetValidationSettings(this.NameTextbox).IsRequired = true;
            
this.EntityValidator.GetValidationSettings(this.NameTextbox).DataType = typeof(string);
this.EntityValidator.GetValidationSettings(this.NameTextbox).ValidationTrigger = Infragistics.Win.Misc.ValidationTrigger.OnValidating;
this.EntityValidator.GetValidationSettings(this.NameTextbox).NotificationSettings.Caption = "My Validation";
this.EntityValidator.GetValidationSettings(this.NameTextbox).NotificationSettings.Action = Infragistics.Win.Misc.NotificationAction.Image;
this.EntityValidator.GetValidationSettings(this.NameTextbox).NotificationSettings.Text = "The Name is required.";

Can you give me some examples here on how to achieve this please.  I've looked at the legacy examples which are pretty basic.  What condition classes are available?

The example uses a RangeCondition which derives from an Object.

Thanks,

Andez