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. WCF and WF
  4. Validation 'before' setting value or issuing command

Validation 'before' setting value or issuing command

Scheduled Pinned Locked Moved WCF and WF
helpcsharpwpfcomtutorial
2 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.
  • G Offline
    G Offline
    greekgoddj
    wrote on last edited by
    #1

    Greetings, I am relatively new to WPF and have an issue relating to validation with DataGrid control. I have read this article (http://msdn.microsoft.com/en-us/magazine/ff714593.aspx) which covers three different ways to validate, but none of them seem to address how to prevent setting a value or calling a undo/redo command before all validation is carried out. I want to ensure that only positive numbers can be entered into the cells. I have set a validation rule that checks if the cell contains a negative number, and I handle the DataGrid's CellEditEnding event to know when to actually change the number used in the model layer. The problem is that CellEditEnding is called before the validation rule. By the time the validation rule catches the problem, the number in the model has already been set. What I need is CellEditEnded, but it appears this event only exist in the Silvelight version of DataGrid. Any ideas? :confused: Thanks

    M 1 Reply Last reply
    0
    • G greekgoddj

      Greetings, I am relatively new to WPF and have an issue relating to validation with DataGrid control. I have read this article (http://msdn.microsoft.com/en-us/magazine/ff714593.aspx) which covers three different ways to validate, but none of them seem to address how to prevent setting a value or calling a undo/redo command before all validation is carried out. I want to ensure that only positive numbers can be entered into the cells. I have set a validation rule that checks if the cell contains a negative number, and I handle the DataGrid's CellEditEnding event to know when to actually change the number used in the model layer. The problem is that CellEditEnding is called before the validation rule. By the time the validation rule catches the problem, the number in the model has already been set. What I need is CellEditEnded, but it appears this event only exist in the Silvelight version of DataGrid. Any ideas? :confused: Thanks

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      greekgoddj wrote:

      I am relatively new to WPF

      Yup got that right you are posting in the wCf forum :laugh: This is not going to help with your problem because I think it is a design issue. This is how I get around it. I never allow inline editing - a datagrid is a display tool only, I either pop a dialog or user another form or use a detail control (haven't got that one worked out yet) to do the editing. This gives me complete control of the object, I have a static method in my viewmodelbase that copies the selected object out of the list<> into the EditableObject. This is them bound to the editing control. If the user cancels I simply throw the editable object away. Save writes the object back to the database and also copies (for edit) the editable object to the selected object. Once again a static method. Caveat the lookup values in the selctedobject need to be retrieved if you do not refresh the list.

      Never underestimate the power of human stupidity RAH

      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