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

Reg Validation

Hi, I am using syncfusion custom control derived from gridControl.How do i validate string, number and currency field validation..? Please send me solution with example. Thanks, Anna

1 Reply

AD Administrator Syncfusion Team June 17, 2005 08:25 AM UTC

You can handle the CurrentCellValidaung event. There use the grid.CurrentCell.ControlText to get teh new value, and set e.Cancel if it is not a proper value. You can also set grid.CurrentCell.ErrorMessage if you want to see a message displayed. Here is a snippet that assume column 5 is an double, and requires any new entry be larger than teh old entry.
private void gridControl1_CurrentCellValidating(object sender, CancelEventArgs e)
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	object oldValue = this.gridControl1[cc.RowIndex, cc.ColIndex].CellValue;
	string newValue = cc.Renderer.ControlText;

	//some check on column 5 - assumes column 5 is of CellType == typeof(double)
	if(cc.ColIndex == 5 && oldValue != null && oldValue.ToString().Length > 0)
		double d;
		if(double.TryParse(newValue, System.Globalization.NumberStyles.Any, null, out d))
			if(d < (double) oldValue)
				e.Cancel = true;
				cc.ErrorMessage = string.Format("value must be larger than {0:F3}", oldValue);

Live Chat Icon For mobile
Up arrow icon