Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8695039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:55:59+00:00 2026-06-13T00:55:59+00:00

I’m having trouble concerning validation in DataGrid. I’m using IDataErrorInfo validation in model classes.

  • 0

I’m having trouble concerning validation in DataGrid. I’m using IDataErrorInfo validation in model classes.

The problem is in editable DataGrid with separate CellTemplate and CellEditingTemplate (Note is a not-null property – validation returns Error if null or empty):

<!-- some other validated columns -->
<DataGridTemplateColumn Header="Note">
    <DataGridTemplateColumn.CellEditingTemplate>
        <DataTemplate>                                    
            <TextBox Name="textBoxNote" Text="{Binding Note, ValidatesOnDataErrors=True}" />                                    
        </DataTemplate>
    </DataGridTemplateColumn.CellEditingTemplate>
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Note}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

On Save button, I check MyObject.Error validation property and if not null I show a MessageBox. The problem is that when changing the first column (not the Note one) to a valid value and then clicking Save button, the .Error property is null – this is expected (although unwanted) behavior because the binding with ValidatesOnDataError on Note property never happened (the TextBox control never even existed!). But if I set the ValidatesOnDataErrors to true on TextBlock then I get the undesired validation on every object shown in a DataGrid (say from a database) that I’m not concerned about; validation can also take a lot of time in this case…

What would be the proper way to handle this issue? I would like to keep validation in model classes (the object should know about whether it’s valid or not). Is there any way to force validation of a row-bound object in codebehind (Save button event)? Or should I somehow initialize .Error on object construction? Any other ideas?

EDIT:
how could I put the whole row (all cells) into edit mode (CellEditingTemplate)? Then, all of the controls would be loaded and databound, this also means validated…

Thanks to all,
DB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:56:01+00:00Added an answer on June 13, 2026 at 12:56 am

    Ok, I managed to revalidate the IDataErrorInfo object – kind of forced IDataErrorInfo validation. Otherwise I could add new object to the DataGrid, but properties (except of the edited ones) never got validated.

    In the superclass of all of my model objects (that extends IDataErrorInfo) I added this method:

    public virtual void Revalidate() // never needed to override though
    {
        Type type = this.GetType();
    
        // "touch" all of the properties of the object - this calls the indexer that checks
        // if property is valid and sets the object's Error property 
        foreach (PropertyInfo propertyInfo in type.GetProperties())
        {                
            var indexerProperty = this[propertyInfo.Name];
        }
    }
    

    Now when the user adds new object to DataGrid I manually call myNewObject.Revalidate() method to set the Error property which I check before saving the object to the database. Maybe this is not the best possible solution, but it works for me very painlessly.

    Thanks and regards,
    DB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.