Articles in this section

How to apply selection based validation on a selected row in WinForms DataGrid (SfDataGrid)?

WinForms DataGrid (SfDataGrid) allows to validate the data and display hints in case of validation is not passed. In case of invalid data, error icon is displayed at the left corner of cell. While selecting a row in WinForms DataGrid (SfDataGrid) If any of the selected rows contains invalid data, displaying the Message Box by customization the SelectionChanged event in WinForms DataGrid (SfDataGrid).

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)
            {
                //check the column is Valid or Invalid
                if (!column.IsValid)
                {
                    MessageBox.Show("Selected Row is Invalid");
                    break;
                }
            }
}   

Shows the selectionbasedvalidation in SfDataGrid

The following screenshot shows while the selected row contains invalid data, displaying the Message Box in WinForms DataGrid (SfDataGrid),


While selected rows contains invalid data, shows message in SfDataGrid

Take a moment to peruse the WinForms DataGrid - Data Validation documentation, where you can find about Data Validation with code examples.

Please refer this link to know about the essential features of WinForms DataGrid.

You can download the example from GitHub

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied