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
45
UltraWinGrid + UltraValidator - how to track which rows are invalid?
posted

I want to display a list of rows to the user, and let them edit those rows as they want.  If a row has bad values then I want to indicate the row is in error; however the user is allowed to keep editing.  When they hit the Apply button, if there are any validation errors for the rows in the grid, the changes are not saved and focus given back to the first row found in error.

I am currently using an UltraValidator control (_validator) to validate that the columns Code and Name are not null & not empty strings.

I have assigned UltraTextEditor controls to the Code and Name columns, and added ValidationSettings for both UltraTextEditors.  When the user is editing the cells in the grid the Code and Name columns correctly display error icons if there are no values.

I cannot use the UltraValidator.Validate function on the Apply button button click; this is because the UltraValidator only checks the values the UltraTextEditors currently contain and not each individual row.  Also, by the time the Apply button click event fires, the controls are invisible and containing empty strings and hence the Validate function always this the controls are in error.


I then tried to validate on the grid's BeforeRowUpdate event.  I receive the exact same problem - UltraValdator.Valudate returns a Validation object with IsValid always false; even when the row is perfectly valid.

My next thought was to put event handlers on the UltraValidator's Validating and ValidationError events and try to record a row-level variable for if any of the cells were in error.  I placed an unbound column on the grid called InError.  On the Validating event I set the grid.ActiveRow.Cells["InError"].Value = "NO".  In the ValidationError event handler I set the grid.ActiveRow.Cells["InError"].Value = "YES".

However this method of trying to track when a validation fails does not work.  If the user enters a value for the Code column but not the Name column, for instance, then moves back into the Code column, the InError cell value is set to "NO" (as the last validated column didn't generate an error...)


How can I keep a record of which rows were in error when the validator validates the row?  I don't want to have to record which individual columns are in error.  I like the way the UltraValidator displays an error icon next to cells in error.

I can always custom code row validation on the grid's BeforeRowUpdate event, track which rows are invalid and set the row back color to a distinctive colour.  However then I have to validate each cell value, code the validation rules, and loose the ErrorImage functionality of the UltraValidator control.

Is there any way to use the UltraValidator control to meet my needs?

Parents Reply Children