This is a migrated thread and some comments may be shown as answers.

how to disable expanding detail rows when current row invalid

1 Answer 132 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 03 Dec 2016, 01:26 PM

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

 

1 Answer, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 06 Dec 2016, 01:26 PM
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.

Regards,
Stefan Nenchev
Telerik by Progress
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
Tags
GridView
Asked by
Randy Hompesch
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Share this question
or