locked
How can I make a WPF DataGrid cell mandatory? RRS feed

  • Question

  • How can I make a WPF DataGrid cell mandatory?

    Example or what I am trying to do is, I have a row for each car and a car has a brand dropdown list cell. This is a required relationship in the Entity frame work model behind the form. if a value is not selected in the dropdown list row, when I try to save the form it crashes because it violated the required relationship rule between car and brand.

    I would like to inform the user this cell needs to have data and prevent the save.

    Thanks in advance guys.

    Cheers Jake

    Sunday, May 6, 2012 3:39 AM

Answers

All replies

  • Hi

    Please refer to this thread for a code sample to read the value in a specific cell:  http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/74332b78-6bfd-4ac9-af85-dfd9bec87a29

    You could eg call this function at the start of your Save function  to determine if the cell contains a value or not. If empty, create an error message in a MessageBox or somewhere on the form and abort the Save function


    Regards Bjoern

    Sunday, May 6, 2012 4:18 PM
  • Hi AustJake

    To achieve this you need to implement DataGridValidation like this

    http://msdn.microsoft.com/en-us/library/ee622975.aspx


    Harshad..... Always 4 U

    Monday, May 7, 2012 5:53 AM
  • Hi AustJake,

    I suggest you to complete WPF validation to prevent save the null value, there are some samples you could refer to:

    http://msdn.microsoft.com/en-us/library/ee622975.aspx

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Sheldon _Xiao Thursday, May 24, 2012 6:24 AM
    Monday, May 7, 2012 6:35 AM
  • Hi AustJake,
     
    I am marking your issue as "Answered", if you have new findings about your issue, please let me know.


    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 24, 2012 6:24 AM