Hi Geoff,
Thank you for your update.
If you want to limit the decimal plases on each key stroke, then handle CurrentCellValidateString. In
your handler test the e.Text to see if it is valid with repsect to your requirements. If it is not, set
e.Cancel to true.If you do not want to do this for each keystroke, but only when the user tries to leave
the cell, then handle the CurrentCellValidating event. In it, get the text from grid.CurrentCell.ControlText, and test it, setting e.Cancel if it is bad.
Below is code that checks for a number in column 1 that is at most 5 places to the left of the decimal, and 2 places to the right of the decimal. You may have to tweak this code, but it should give you the idea. It will not allow you to type an invalid character.
Please refer this code snippets:
private void
gridControl1_CurrentCellValidateString(object sender, GridCurrentCellValidateStringEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if (cc.ColIndex != 1)
{
return;
}
try
{
if (e.Text != ".")
{
double d = double.Parse(e.Text);
}
}
catch
{
e.Cancel = true;
return;
}
int dec = e.Text.IndexOf('.');
int len = e.Text.Length;
if (len > 8)
{
e.Cancel = true;
}
else if (dec > 4)
{
e.Cancel = true;
}
else if (dec == -1 & len > 5)
{
e.Cancel = true;
}
else if (dec > -1 & dec < len - 3)
{
e.Cancel = true;
}
}
}
Please refer the sample which implements the above said feature:
http://websamples.syncfusion.com/samples/Grid.Windows/F68595/main.htmKindly let us know if you need any further assistance.
Thank you for using Syncfusion Products.
Regards,
Jeba.