We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GDBG: ValidateFailed event

How can I create a custom errormessage if the validation for a cell fails? I got a messagebox saying "xx is not a valid value for Double" when I type "xx" in a "double-cell". I tested th following code in the ValidateFailed-event: MessageBox.Show("my custom errormessage","my title",0,MessageBoxIcon.Warning); e.Handled=true; That works if I move to the next cell by clicking in it with the mouse, but if I press TAB or Enter I still got the "xx is not a vaild..." messagebox... /Johan

6 Replies

AD Administrator Syncfusion Team May 5, 2004 10:52 AM UTC

In ValidateFailed, try setting this.gridDataBoundGrid1.CurrentCell.ErrorMessage = "my error message...";


JD Johan Djupmarker May 5, 2004 12:15 PM UTC

It works when I hit TAB, but I still got "xx is not a valid value for Double" if I hit Enter. /Johan


AD Administrator Syncfusion Team May 5, 2004 04:13 PM UTC

This worked for me in a sample (tabbing, entering, and clicking). Handle the CurrentCellValidating event and validate the value yourself. You can cancel it and set the ErrorMessage if the value is not a double.
private void gridDataBoundGrid1_CurrentCellValidating(object sender, CancelEventArgs e)
{
	GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
	if(cc.RowIndex > 0 && cc.ColIndex == 2)
	{
		double d;
		if(!double.TryParse(cc.Renderer.ControlText, 
			System.Globalization.NumberStyles.Any, null, out d))
		{
			e.Cancel = true;
			cc.ErrorMessage = "MyMessage";
		}
}


JD Johan Djupmarker May 6, 2004 03:37 AM UTC

It works, but require code for every column containing "double-values". Does the cc-object contain information about the cells datatype so I can write a function that validates every numeric column? /Johan


AD Administrator Syncfusion Team May 6, 2004 05:20 AM UTC

You can try using int field = this.grid.Binder.ColIndexToField(cc.ColIndex); Type t = this.grid.GridBoundColumns[field].StyleInfo.CellValueType; // t now has the System.Type // if you have not explicitly added GridBoundColumns, then use grid.Binder.InternalColumns instead of grid.GridBoundColumns


JD Johan Djupmarker May 6, 2004 06:35 AM UTC

Great, works fine! /Johan

Loader.
Live Chat Icon For mobile
Up arrow icon