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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GDBG: ValidateFailed event

Thread ID:

Created:

Updated:

Platform:

Replies:

13644 May 5,2004 07:22 AM UTC May 6,2004 06:35 AM UTC WinForms 6
loading
Tags: GridControl
Johan Djupmarker
Asked On May 5, 2004 07:22 AM UTC

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

Administrator [Syncfusion]
Replied On May 5, 2004 10:52 AM UTC

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

Johan Djupmarker
Replied On 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

Administrator [Syncfusion]
Replied On 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";
		}
}

Johan Djupmarker
Replied On 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

Administrator [Syncfusion]
Replied On 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

Johan Djupmarker
Replied On May 6, 2004 06:35 AM UTC

Great, works fine! /Johan

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;