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

Validate empty input in new cells

Hi, I want to validate empty input and show an error message when input is equals to "". So, I use the CurrentCellValidating event and cancel the event if necessary. This works only when the cell was initially set to something other than an empty string(""). But in my case: the CurrentCellValidating event isn''t triggered and even if sometimes, the RejectChanges prevents the event from being triggered the next times. I do the following: Add a row with 3 cells, and set the input into the first cell: gridTemplates.Focus(); gridTemplates.CurrentCell.MoveTo(row, 1); gridTemplates.CurrentCell.Activate(row, 1, GridSetCurrentCellOptions.ScrollInView); When the edited cell wasn''t edited and the user intended to go to the next cell, the CurrentCellValidating event isn''t triggered. This only happens if I initially set the cells''s value (CurrentCellRenderer.ControlValue) to something. Next, when I press the escape key, this doesn''t work either. Any hints how I can get to this? Thanks in advance Michael

1 Reply

AD Administrator Syncfusion Team November 24, 2004 08:15 AM UTC

Here is a general idea. It may need a little tweaking as you try to implement it. Try handling grid.CurrentCellMoving. In your handler, check if grid.CurrentCell.IsModified is false (which means your user did not change anything, and may be trying the leave an empty cell). In this case, if grid[grid.CurrentCell.RowIndex, grid.CurrentCell.ColIndex].Text is empty, the set grid.CurrentCell.ErrorMessage and set e.Cancel = true.

Live Chat Icon For mobile
Up arrow icon