Is selected row valid

Is there an easy way of checking if a row selected (preferably in SelectionChanged) has any invalid cell values?   

I'm using DataAnnotations in my model and have the grid view showing datavalidation warnings InView.  I would like to disable another control if any of the selected rows contains invalid data.  I can obviously check the underlying data but as the grid has already done that .....

Many Thanks

3 Replies 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team January 21, 2021 12:10 PM UTC

Hi Russ, 
Thank you for contacting Syncfusion support.

Your requirement can be achieved by customization in SfDataGrid.SelectionChanged event. Please refer the below code snippet, 
sfDataGrid.SelectionChanged += SfDataGrid_SelectionChanged;

private void SfDataGrid_SelectionChanged(object sender, Syncfusion.WinForms.DataGrid.Events.SelectionChangedEventArgs e) 
{ 
            var rowGenerator = (RowGenerator)this.sfDataGrid.TableControl.GetType().GetProperty("RowGenerator", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(this.sfDataGrid.TableControl); 
 
            //get the selectedItem record 
            var dataRow = rowGenerator.Items.FirstOrDefault(row => row.RowData==this.sfDataGrid.SelectedItem);            
           
            foreach (var column in dataRow.VisibleColumns) 
            { 
                if (!column.IsValid) 
                { 
                    MessageBox.Show("Selected Row is Invalid"); 
                    break; 
                } 
            } 
}    
You can refer the following user guide documentation to data validation support in SfDataGrid.

UG Link: https://help.syncfusion.com/windowsforms/datagrid/datavalidation 
We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Marked as answer

RU Russ January 21, 2021 12:27 PM UTC

Awesome.  Thanks


VS Vijayarasan Sivanandham Syncfusion Team January 22, 2021 10:03 AM UTC

Hi Russ, 
 
Thanks for the update. 
 
We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you😊. 
 
Regards, 
Vijayarasan S 


Loader.
Up arrow icon