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.
Unfortunately, activation email could not send to your email. Please try again.

GDBG: ValidateFailed event

Thread ID:

Created:

Updated:

Platform:

Replies:

13644 May 5,2004 03:22 AM May 6,2004 02:35 AM Windows Forms 6
loading
Tags: GridControl
Johan Djupmarker
Asked On May 5, 2004 03:22 AM

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 06:52 AM

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

Johan Djupmarker
Replied On May 5, 2004 08:15 AM

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 12:13 PM

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 5, 2004 11:37 PM

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 01:20 AM

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 02:35 AM

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.

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.

;