Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Elegant Grid Tech Support » Cell Validation Collapse All
Subject Author Date
Jake G. Jul 25, 2006 - 1:49 PM

Hi,

Can somebody show me how to use the ValidateEditingCellData event? Is it the right tool for validating user input e.g in a text edit cell?

Technical Support Jul 26, 2006 - 6:40 AM

Here is a simple C# project that illustrates the issue. Please build and run the application. You will see that if you type a space in any cell in the Name column, the value will not be committed to the bound data. This is achieved because the ValidateEditingCellData event is handled in this way:

private void boundGridControl1_ValidateEditingCellData(object sender, 
   Elegant.Grid.ValidateCellDataEventArgs e)
{
   if(e.Cell.Column != NameColumn)
       return;

   if(e.ValidationReason == DataValidationReason.BeforeCommit &&
       e.DataValue.ToString().IndexOf(’ ’) != -1)
   {
       e.InvalidDataBehavior = CellInvalidDataBehavior.None;
       e.Valid = false;

       MessageBox.Show("The name cannot contain spaces.");
   }
}
If you mean something else, just contact us and we will help you find the most appropriate solution.

Jake G. Jul 26, 2006 - 11:35 AM

Many thanks. Works like a dream!