示例#1
0
        public override ValidationResult Validate(object value,
                                                  System.Globalization.CultureInfo cultureInfo)
        {
            Studente s = (value as BindingGroup).Items[0] as Studente;

            if (s.Anni > 70 || s.Anni < 3)
            {
                return(new ValidationResult(false,
                                            "L'età deve essere compresa tra 3 ai 70 anni."));
            }
            else
            {
                return(ValidationResult.ValidResult);
            }
        }
 private void btnCreaStud_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         int eta = int.Parse(txtBoxEta.Text);
         if (eta < 3 || eta > 70)
         {
             throw new ArgumentOutOfRangeException("Anni", eta, "Età inserita non accettabile");
         }
         if (txtBoxNome.Text == "")
         {
             throw new FormatException("Inserire un nome perfavore.");
         }
         Studente s = new Studente(++id, txtBoxNome.Text, eta);
         students.Add(s);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }