how to disable expanding detail rows when current row invalid

2 posts, 0 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    148 posts
    Member since:
    Nov 2008

    Posted 03 Dec 2016 Link to this post

    Ok, so I have gridview with IsReadOnly = True. I allow the user to expand the rowdetails and edit data using a raddataform. This the bound object for this form has dataannotations which are used to validate the record. Suppose I have a required field that is left blank. The form recognizes the problem and disables the save button, but I'm still allowed to navigate to another row. How to prevent this (mvvm style ... of course!)?

    Thanks ... Ed


  2. Stefan Nenchev
    Stefan Nenchev avatar
    665 posts

    Posted 06 Dec 2016 Link to this post

    Hello Randy,

    You can utilize the SelectionChanging event of the RadGridView and set its e.Cancel argument to true in order to not enable the change of the selection in a certain scenario. For Example:
    private void clubsGrid_SelectionChanging(object sender, SelectionChangingEventArgs e)
               if (e.RemovedItems.Count > 0)
                   var oldItem = e.RemovedItems[0] as Club;
                   if (oldItem.Name.ToString().Length < 1 || oldItem.StadiumCapacity > 70000)
                       e.Cancel = true;

    You can use the EventToCommandBehavior to keep the MVVM pattern intact. I have attached a sample for your reference. Try leaving the "Name" of the Club empty.

    Stefan Nenchev
    Telerik by Progress
    Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Back to Top