public void LoadValidators(ValidatorCollection validators) { // Note: validators should contain all validators under // the jurisdiction of the BaseContainerValidator so // we can handle both where a control becomes valid and // where a control becomes invalid. If we only get // the invalid controls, we can't display controls that were // valid at the time but become invalid // If list currently has items then deregister the // Validate event handler if( this.validationErrorsList.Items.Count > 0 ) { foreach( BaseValidator validator in this.validationErrorsList.Items ) { validator.Validated -= new EventHandler(BaseValidator_Validated); } } // Clear the list this.validationErrorsList.Items.Clear(); // Add new validators and register the Validate // event handler foreach(BaseValidator validator in validators ) { if( !validator.IsValid ) { this.validationErrorsList.Items.Add(validator); } validator.Validated += new EventHandler(BaseValidator_Validated); } }
public void LoadValidators(ValidatorCollection validators) { // Note: validators should contain all validators under // the jurisdiction of the BaseContainerValidator so // we can handle both where a control becomes valid and // where a control becomes invalid. If we only get // the invalid controls, we can't display controls that were // valid at the time but become invalid // If list currently has items then deregister the // Validate event handler if (this.validationErrorsList.Items.Count > 0) { foreach (BaseValidator validator in this.validationErrorsList.Items) { validator.Validated -= new EventHandler(BaseValidator_Validated); } } // Clear the list this.validationErrorsList.Items.Clear(); // Add new validators and register the Validate // event handler foreach (BaseValidator validator in validators) { if (!validator.IsValid) { this.validationErrorsList.Items.Add(validator); } validator.Validated += new EventHandler(BaseValidator_Validated); } }
/// <summary> /// Creates a synchronized (thread-safe) wrapper for a /// <c>ValidatorCollection</c> instance. /// </summary> /// <returns> /// An <c>ValidatorCollection</c> wrapper that is synchronized (thread-safe). /// </returns> public static ValidatorCollection Synchronized(ValidatorCollection list) { if (list == null) { throw new ArgumentNullException("list"); } return(new SyncValidatorCollection(list)); }
/// <summary> /// Creates a read-only wrapper for a /// <c>ValidatorCollection</c> instance. /// </summary> /// <returns> /// An <c>ValidatorCollection</c> wrapper that is read-only. /// </returns> public static ValidatorCollection ReadOnly(ValidatorCollection list) { if (list == null) { throw new ArgumentNullException("list"); } return(new ReadOnlyValidatorCollection(list)); }
/// <summary> /// Creates a shallow copy of the <see cref="ValidatorCollection"/>. /// </summary> public virtual object Clone() { ValidatorCollection newColl = new ValidatorCollection(m_count); Array.Copy(m_array, 0, newColl.m_array, 0, m_count); newColl.m_count = m_count; newColl.m_version = m_version; return(newColl); }
/// <summary> /// Adds the elements of another <c>ValidatorCollection</c> to the current <c>ValidatorCollection</c>. /// </summary> /// <param name="x">The <c>ValidatorCollection</c> whose elements should be added to the end of the current <c>ValidatorCollection</c>.</param> /// <returns>The new <see cref="ValidatorCollection.Count"/> of the <c>ValidatorCollection</c>.</returns> public virtual int AddRange(ValidatorCollection x) { if (m_count + x.Count >= m_array.Length) { EnsureCapacity(m_count + x.Count); } Array.Copy(x.m_array, 0, m_array, m_count, x.Count); m_count += x.Count; m_version++; return(m_count); }
public static void Register(BaseValidator validator, Form hostingForm) { // Create form bucket if it doesn't exist if (_validators[hostingForm] == null) { _validators[hostingForm] = new ValidatorCollection(); } // Add this validator to the list of registered validators ValidatorCollection validators = (ValidatorCollection)_validators[hostingForm]; validators.Add(validator); }
public static void DeRegister(BaseValidator validator, Form hostingForm) { // Remove this validator from the list of registered validators ValidatorCollection validators = (ValidatorCollection)_validators[hostingForm]; if (validators != null) { validators.Remove(validator); // Remove form bucket if all validators on the form are de-registered if (validators.Count == 0) { _validators.Remove(hostingForm); } } }
public static ValidatorCollection GetValidators(Form hostingForm, Control container, ValidationDepth validationDepth) { ValidatorCollection validators = ValidatorManager.GetValidators(hostingForm); ValidatorCollection contained = new ValidatorCollection(); foreach (BaseValidator validator in validators) { // Only validate BaseValidators hosted by the container I reference if (IsParent(container, validator.ControlToValidate, validationDepth)) { contained.Add(validator); } } return contained; }
public static ValidatorCollection GetValidators(Form hostingForm, Control container, ValidationDepth validationDepth) { ValidatorCollection validators = ValidatorManager.GetValidators(hostingForm); ValidatorCollection contained = new ValidatorCollection(); foreach (BaseValidator validator in validators) { // Only validate BaseValidators hosted by the container I reference if (IsParent(container, validator.ControlToValidate, validationDepth)) { contained.Add(validator); } } return(contained); }
// Support validation in flattened tab index order protected ValidatorCollection Sort(ValidatorCollection validators) { // Sort validators into flattened tab index order // using the BaseValidatorComparer ArrayList sorted = new ArrayList(); foreach (BaseValidator validator in validators) { sorted.Add(validator); } sorted.Sort(new BaseValidatorComparer()); ValidatorCollection sortedValidators = new ValidatorCollection(); foreach (BaseValidator validator in sorted) { sortedValidators.Add(validator); } return(sortedValidators); }
/// <summary> /// Adds the elements of another <c>ValidatorCollection</c> to the current <c>ValidatorCollection</c>. /// </summary> /// <param name="x">The <c>ValidatorCollection</c> whose elements should be added to the end of the current <c>ValidatorCollection</c>.</param> /// <returns>The new <see cref="ValidatorCollection.Count"/> of the <c>ValidatorCollection</c>.</returns> public virtual int AddRange(ValidatorCollection x) { if (m_count + x.Count >= m_array.Length) EnsureCapacity(m_count + x.Count); Array.Copy(x.m_array, 0, m_array, m_count, x.Count); m_count += x.Count; m_version++; return m_count; }
/// <summary> /// Creates a synchronized (thread-safe) wrapper for a /// <c>ValidatorCollection</c> instance. /// </summary> /// <returns> /// An <c>ValidatorCollection</c> wrapper that is synchronized (thread-safe). /// </returns> public static ValidatorCollection Synchronized(ValidatorCollection list) { if(list==null) throw new ArgumentNullException("list"); return new SyncValidatorCollection(list); }
/// <summary> /// Creates a read-only wrapper for a /// <c>ValidatorCollection</c> instance. /// </summary> /// <returns> /// An <c>ValidatorCollection</c> wrapper that is read-only. /// </returns> public static ValidatorCollection ReadOnly(ValidatorCollection list) { if(list==null) throw new ArgumentNullException("list"); return new ReadOnlyValidatorCollection(list); }
internal ReadOnlyValidatorCollection(ValidatorCollection list) { m_collection = list; }
protected override void Summarize(object sender, SummarizeEventArgs e) { // Don’t validate if no validators were passed if (e.Validators.Count == 0) { return; } BaseContainerValidator extendee = (BaseContainerValidator)sender; ValidationSummaryDisplayMode displayMode = GetDisplayMode(extendee); ValidatorCollection validators = e.Validators; // Make sure there are validators if ((validators == null) || (validators.Count == 0)) { return; } string errorMessage = GetErrorMessage(extendee); string errorCaption = GetErrorCaption(extendee); // Get error text, if provided if (errorMessage == null) { errorMessage = ""; } // Get error caption, if provided if (errorCaption == null) { errorCaption = ""; } // Build summary message body string errors = ""; if (displayMode == ValidationSummaryDisplayMode.Simple) { // Build Simple message errors = errorMessage; } else { // Build List, BulletList or SingleParagraph foreach (object validator in base.Sort(validators)) { BaseValidator current = (BaseValidator)validator; if (!current.IsValid) { switch (displayMode) { case ValidationSummaryDisplayMode.List: errors += string.Format("{0}\n", current.ErrorMessage); break; case ValidationSummaryDisplayMode.BulletList: errors += string.Format("- {0}\n", current.ErrorMessage); break; case ValidationSummaryDisplayMode.SingleParagraph: errors += string.Format("{0}. ", current.ErrorMessage); break; } } } // Prepend error message, if provided if ((errors != "") && (errorMessage != "")) { errors = string.Format("{0}\n\n{1}", errorMessage.Trim(), errors); } } // Display summary message // "if( errors.Trim().Length > 0 )" thanks to John V. Barone and Jorge Matos if (errors.Trim().Length > 0) { MessageBox.Show(errors, errorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
internal SyncValidatorCollection(ValidatorCollection list) { m_root = list.SyncRoot; m_collection = list; }
public SummarizeEventArgs(ValidatorCollection validators, Form hostingForm) { Validators = validators; HostingForm = hostingForm; }
/// <summary> /// Initializes a new instance of the <c>Enumerator</c> class. /// </summary> /// <param name="tc"></param> internal Enumerator(ValidatorCollection tc) { m_collection = tc; m_index = -1; m_version = tc.m_version; }
public override int AddRange(ValidatorCollection x) { throw new NotSupportedException("This is a Read Only Collection and can not be modified"); }
/// <summary> /// Creates a shallow copy of the <see cref="ValidatorCollection"/>. /// </summary> public virtual object Clone() { ValidatorCollection newColl = new ValidatorCollection(m_count); Array.Copy(m_array, 0, newColl.m_array, 0, m_count); newColl.m_count = m_count; newColl.m_version = m_version; return newColl; }
/// <summary> /// Initializes a new instance of the <c>ValidatorCollection</c> class /// that contains elements copied from the specified <c>ValidatorCollection</c>. /// </summary> /// <param name="c">The <c>ValidatorCollection</c> whose elements are copied to the new collection.</param> public ValidatorCollection(ValidatorCollection c) { m_array = new BaseValidator[c.Count]; AddRange(c); }
public override int AddRange(ValidatorCollection x) { lock(this.m_root) return m_collection.AddRange(x); }
// Support validation in flattened tab index order protected ValidatorCollection Sort(ValidatorCollection validators) { // Sort validators into flattened tab index order // using the BaseValidatorComparer ArrayList sorted = new ArrayList(); foreach (BaseValidator validator in validators) { sorted.Add(validator); } sorted.Sort(new BaseValidatorComparer()); ValidatorCollection sortedValidators = new ValidatorCollection(); foreach (BaseValidator validator in sorted) { sortedValidators.Add(validator); } return sortedValidators; }
public override int AddRange(ValidatorCollection x) { lock (this.m_root) return(m_collection.AddRange(x)); }