# C1.WPF.FlexGrid.C1FlexGrid.ShowErrors

## Content

<div class="doc-site-dotnet-api-container">



<h1 id="C1_WPF_FlexGrid_C1FlexGrid_ShowErrors_" data-uid="C1.WPF.FlexGrid.C1FlexGrid.ShowErrors*">ShowErrors Property
</h1>
<div class="markdown level0 summary"></div>
<div class="markdown level0 conceptual"></div>



<a id="C1_WPF_FlexGrid_C1FlexGrid_ShowErrors_" data-uid="C1.WPF.FlexGrid.C1FlexGrid.ShowErrors*"></a>
<h4 id="C1_WPF_FlexGrid_C1FlexGrid_ShowErrors" data-uid="C1.WPF.FlexGrid.C1FlexGrid.ShowErrors">ShowErrors</h4>
<div class="markdown level1 summary"><p>Gets or sets a value that determines whether the grid should display
validation errors.</p>
</div>
<div class="markdown level1 conceptual"></div>
<h5 class="declaration">Declaration</h5>
<div class="codewrapper">
  <pre><code class="lang-csharp hljs">public bool ShowErrors { get; set; }</code></pre>
</div>
<div class="codewrapper">
  <pre><code class="lang-vbnet hljs">Public Property ShowErrors As Boolean</code></pre>
</div>
<h5 id="C1_WPF_FlexGrid_C1FlexGrid_ShowErrors_remarks">Remarks</h5>
<div class="markdown level1 remarks"><pre><code>&lt;p&gt;Validation errors may be triggered in several ways:&lt;/p&gt;
&lt;p&gt;If a property setter in a data item throws an exception, an error message is 
</code></pre>
<p>displayed by the cell editor and the editor remains active until the error is corrected
or until the changes are canceled.</p>
<p>If the data item implements the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.idataerrorinfo">IDataErrorInfo</a> 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.</p>
<p>If the data item implements the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.inotifydataerrorinfo">INotifyDataErrorInfo</a> interface,
then the item can raise column-level or item-level validation errors as above, and it
can raise those validation errors asynchronously. <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.inotifydataerrorinfo">INotifyDataErrorInfo</a>
is more complex and harder to implement than <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.idataerrorinfo">IDataErrorInfo</a>.</p>
</div>
<h5 id="C1_WPF_FlexGrid_C1FlexGrid_ShowErrors_examples">Examples</h5>
<p>The code below shows how you can implement validation in your data classes using plain
exceptions and the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.idataerrorinfo">IDataErrorInfo</a> interface. For an example of validation
using the <a class="xref" href="https://learn.microsoft.com/dotnet/api/system.componentmodel.inotifydataerrorinfo">INotifyDataErrorInfo</a> interface, please see
<a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx">http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifydataerrorinfo(v=vs.95).aspx</a>.</p>
<pre><code class="lang-csharp">    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 &lt;= 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 &lt;= 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 &lt; Cost
                ? "Price must be greater than Cost!"
                : null;
        }
    }
}</code></pre>

</div>
