Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Re-validating DataGrid after programmaticallychanging row source

Re-validating DataGrid after programmaticallychanging row source

Scheduled Pinned Locked Moved WPF
questioncsharpwpfcomdiscussion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jchalfant
    wrote on last edited by
    #1

    Validation in Windows Presentation Foundation[^] and http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^] were both good resources for custom validation rules on a DataGrid, but if I programmatically change values in the row source, the row doesn't re-validate. If I change a cell value by manually editing it, on the other hand, validation will fire. How can I force validation even when the user is not directly manipulating the cell? I have my custom validation rule ValidationStep set to CommittedValue and UpdatedValue. I've also tried BeginEdit and CommitEdit after changes are made. Any thoughts?

    M 1 Reply Last reply
    0
    • J jchalfant

      Validation in Windows Presentation Foundation[^] and http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^] were both good resources for custom validation rules on a DataGrid, but if I programmatically change values in the row source, the row doesn't re-validate. If I change a cell value by manually editing it, on the other hand, validation will fire. How can I force validation even when the user is not directly manipulating the cell? I have my custom validation rule ValidationStep set to CommittedValue and UpdatedValue. I've also tried BeginEdit and CommitEdit after changes are made. Any thoughts?

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Does the class representing a row of data implement and use the INotifyPropertyChanged interface?

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      J 1 Reply Last reply
      0
      • M Mark Salsbery

        Does the class representing a row of data implement and use the INotifyPropertyChanged interface?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        J Offline
        J Offline
        jchalfant
        wrote on last edited by
        #3

        It's an EF ComplexObject using the default auto generated code. It is derived from StructuralObject, which is derived from INotifyPropertyChanging and implements the INotifyPropertyChanged. I checked the Properties I'm changing and they all call the ReportPropertyChanged method after a change occurs. I think this has more to do with the way I'm updating the row source. I'm allowing the user to open a context menu through the ValidationErrorTemplate and select various options. The change occurs in the MenuItem click event. If I change focus to anything in the Window using the mouse, the row will validate.

        M 1 Reply Last reply
        0
        • J jchalfant

          It's an EF ComplexObject using the default auto generated code. It is derived from StructuralObject, which is derived from INotifyPropertyChanging and implements the INotifyPropertyChanged. I checked the Properties I'm changing and they all call the ReportPropertyChanged method after a change occurs. I think this has more to do with the way I'm updating the row source. I'm allowing the user to open a context menu through the ValidationErrorTemplate and select various options. The change occurs in the MenuItem click event. If I change focus to anything in the Window using the mouse, the row will validate.

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          The validation system is really for validating user input so there's not an easy provision for validating code-produced data, since that data should be validated by the code anyway. You may find a solution in these... Validation Rules for WPF and C#[^] force a Binding to validate[^]

          Mark Salsbery :java:

          J 1 Reply Last reply
          0
          • M Mark Salsbery

            The validation system is really for validating user input so there's not an easy provision for validating code-produced data, since that data should be validated by the code anyway. You may find a solution in these... Validation Rules for WPF and C#[^] force a Binding to validate[^]

            Mark Salsbery :java:

            J Offline
            J Offline
            jchalfant
            wrote on last edited by
            #5

            You're right. I'm not using the validator as intended. There are plenty of things I can do in a cell data template to get my intended functionality. Thanks for the help. It didn't get me to my original goal, but illuminated the error of my ways and saved me time digging for an answer that doesn't exist.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups