Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2715
Type conversion error exception handling
posted

Hi!

I have a grid bound to a table, with a column called "Price" of type Int. In the CellUpdate event I'm treating the cases of when incorect data (negative, or characters) is inserted in a cell in that column. But before reaching the CellUpdate event the grid throws an error that a conversion error has ocurred, and only after this the cell update triggers. So I get 2 error messages, and I want to get rid of the first one, throws by the conversion error.

How could I solve this ?

Thanks!

  • 69832
    Verified Answer
    Offline posted

    There are several different approaches to this. One is to use character masking (see UltraGridColumn.MaskInput), whereby the cell disallows user entry of (for example) non-numeric characters.

    Another approach is to handle the BeforeExitEditMode event, validate the value therein, and set the Cancel property of the event arguments to true if the value does not meet a certain criteria. If you do this, you'll want to use the UltraGrid.ActiveCell.EditorResolved.CurrentEditText property, which will give you the raw, unvalidated value entered by the user.