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
543
WinGrid cell validation
posted
Hi,
in my application I use a WinGrid to collect informations about a set of properties. The grid has two columns, one for the name of the properties, and the other for the values. So, each row in the grid represents a single property. Depending on property type and attributes, the cell holding value has a particular style and editor (ColumnStyle.Double, ColumnStyle.Date, ColumnStyle.DropDown, ...).

I would like to set a max length for text-type properties, but unfortunately it seems to be a column-only attribute. So I have to make a little validation on my fields, but I can't find a pretty solution to the following questions:

- which is the best event I can use to trap all changes to my value fields? Now I'm using 'BeforeCellUpdate', but it doesn't allow me to force the cursor to remain in the not-validating cell. So I tried to use 'BeforeExitEditMode', but it doesn't fire on DropDown fields...

- how can I replace the value that doesn't validate (value too long, for example) with a correct value (the same value, trimmed, for example), in which event? I tried to set a new value to the cell in 'BeforeCellUpdate', but it raises an exception:
"Value property can not be assigned while BeforeCellUpdate event is in progress".

Please let me know if I'm missing something... :)

Thank you for your time,
Valentina
Parents
  • 37774
    Verified Answer
    posted

    Valentina,

    Generally the BeforeExitEditMode event is the best place to perform this logic since you can prevent the user from moving to another cell until a valid value is entered.  This isn't firing after a DropDown is closed because at this point the cell would still be in edit mode; you could use the AfterCellListCloseUp if you need to immediately perform logic here.

    As for setting a new value on a cell, it would make sense that you can't assign a value in the BeforeCellUpdate since this would cause a recursive situation.  You could likely update the value in the BeforeExitEditMode event as well.

    -Matt

Reply Children
No Data