FlexSheet for WPF | ComponentOne
C1.WPF.FlexGrid Namespace / C1FlexGrid Class / ShowErrors Property
Example

In This Topic
    ShowErrors Property
    In This Topic
    Gets or sets a value that determines whether the grid should display validation errors.
    Syntax
    'Declaration
     
    
    Public Property ShowErrors As Boolean
    public bool ShowErrors {get; set;}
    Remarks

    Validation errors may be triggered in several ways:

    If a property setter in a data item throws an exception, an error message is displayed by the cell editor and the editor remains active until the error is corrected or until the changes are canceled.

    If the data item implements the System.ComponentModel.IDataErrorInfo interface, then the item can raise column-level validation errors by implementing the default indexer and returning a column-specific error message (also displayed in the cell editor), or it can trigger item-level validation errors by setting the Error property to an error message. In this case, the error is not specific to any columns, and the error is displayed as an icon in the first cell in the row header.

    If the data item implements the System.ComponentModel.INotifyDataErrorInfo interface, then the item can raise column-level or item-level validation errors as above, and it can raise those validation errors asynchronously. System.ComponentModel.INotifyDataErrorInfo is more complex and harder to implement than System.ComponentModel.IDataErrorInfo.

    Example
    The code below shows how you can implement validation in your data classes using plain exceptions and the System.ComponentModel.IDataErrorInfo interface. For an example of validation using the System.ComponentModel.INotifyDataErrorInfo interface, please see http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx.
    public class Product : 
            INotifyPropertyChanged, 
            IEditableObject,
            IDataErrorInfo
    {
        // ** method 1: throw an exception when setting the Price to negative values
        public double? Price
        {
            get { return (double?)GetValue("Price"); }
            set
            {
                if (value <= 0)
                { 
                    throw new Exception("Price must be greater than zero!");
                }
                SetValue("Price", value); 
            }
        }
        
        // ** method 2: return errors for specific columns
        string IDataErrorInfo.this[string columnName]
        {
            get
            {
                string msg = null;
                switch (columnName)
                {
                    case "Cost":    
                        if (Cost <= 0)
                        {
                            msg = "Cost must be greater than zero!";
                        }
                        break;
                }
                return msg;
            }
        }
        
        // ** method 3: return errors for the entire row 
        // (validation depends on multiple columns)
        string IDataErrorInfo.Error
        {
            get
            {
                return Price < Cost
                    ? "Price must be greater than Cost!"
                    : null;
            }
        }
    }
    See Also