How to show row validation without hovering on error icon in WinForms DataGrid?
By default, WinForms DataGrid (SfDataGrid) displays validation error tooltip when hovering on the error icon in the row header cell. However, you can show tooltip immediately after the value is changed without hovering on the row header cell by using SfToolTip.
C#
SfToolTip validationToolTip = new SfToolTip(); ToolTipInfo toolTipInfo1 = new ToolTipInfo(); ToolTipItem toolTipItem1 = new ToolTipItem(); /// <summary> /// Initializes the new instance for the Form. /// </summary> public Form1() { InitializeComponent(); sfDataGrid1.DataSource = new OrderInfoCollection().OrdersListDetails; toolTipInfo1.RightToLeft = RightToLeft.Yes; toolTipItem1.Style.BackColor = Color.Red; toolTipItem1.Style.ForeColor = Color.White; toolTipInfo1.Items.AddRange(new ToolTipItem[] { toolTipItem1 }); this.sfDataGrid1.RowValidating += SfDataGrid1_RowValidating; this.sfDataGrid1.CurrentCellEndEdit += SfDataGrid1_CurrentCellEndEdit; } private void SfDataGrid1_CurrentCellEndEdit(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellEndEditEventArgs e) { validationToolTip.Hide(); } private void SfDataGrid1_RowValidating(object sender, Syncfusion.WinForms.DataGrid.Events.RowValidatingEventArgs e) { if ((e.DataRow.RowData as OrderInfo).Quantity == 0) { e.IsValid = false; e.ErrorMessage = "Quantity is Zero"; var X = sfDataGrid1.TableControl.GetCellRectangle(e.DataRow.RowIndex, 0, false).X; var Y = sfDataGrid1.TableControl.GetCellRectangle(e.DataRow.RowIndex, 0, false).Y; toolTipItem1.Text = e.ErrorMessage; validationToolTip.Show(toolTipInfo1, this.sfDataGrid1.PointToScreen(new Point(X, Y))); } }
Take a moment to peruse the documentation, where you can find about data validation in SfDataGrid, with code examples.
You can download the example from GitHub
Conclusion
I hope you enjoyed learning about how to show row validation without hovering on the error icon in WinForms DataGrid.
You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms DataGrid documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!