How to customize the error message in WinForms GridControl?
Customize the error message
When an invalid data format or data type is entered in the WinForms GridControl, an error message is displayed. The error message is like xx is not a valid value for Double. This error message can be customized.
Solution
You can handle the CurrentCellValidating event, validate, and set the error message. The following code example gives a customized error message when a value other than a double is entered.
void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
//Set the dataformat to the column 2.
if (cc.ColIndex == 2)
{
string newvalue = cc.Renderer.ControlText;
try
{
double d = double.Parse(newvalue);
}
catch
{
//Display the error message.
cc.ErrorMessage = "u r entered invalid dataformat";
e.Cancel = true;
}
}
}Private Sub gridControl1_CurrentCellValidating(ByVal sender As Object, ByVal e As CancelEventArgs)
Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
'Set the dataformat to the column 2.
If cc.ColIndex = 2 Then
Dim newvalue As String = cc.Renderer.ControlText
Try
Dim d As Double = Double.Parse(newvalue)
Catch
'Display the error message.
cc.ErrorMessage = "u r entered invalid dataformat"
e.Cancel = True
End Try
End If
End SubOn applying
the properties, the grid looks like the following screenshot.

Figure 1: Custom message when invalid data is entered
Samples:
C#: Customizing the error message
VB: Customizing the error message
Conclusion
I hope you enjoyed learning about how to customize the
error message in WinForms GridControl.
You can refer
to our WinForms GridControl feature tour page to know about
its other groundbreaking feature representations and WinForms GridControl documentation, and how
to quickly get started for configuration specifications.
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 clarification, 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!