hi, i have looked at the other posts regarding validation and your validation video. i do understand the row_validation and cell_validation events. However, in order to validate the entries AND mark the errors, i have to use the validation code twice which i dont want to do.
My test code is shown below. Have also attached a screenshot.
Here's what i am trying to do:
in the grid2_RowValidating event i am validating and preventing user to go to next row. i would like to "mark/color" the cell with the error. I tried all the Style properties but only the forecolor works. (i have commented the lines not working)
So, in addition to RowValidating event, i decided to use the grid2_ViewCellFormatting event to validate and color the cell with the error.
This is working but i dont understand why i have to validate twice. (once in the RowValidating event to prevent them to go to the next row and again in the ViewCellFormatting event to "color" the cell)
Am i doing something wrong? Why am i not able to set the Style Properties directly from within the RowValidating. I am using the Q2 2011 version (latest)
My test code is shown below. Have also attached a screenshot.
Here's what i am trying to do:
in the grid2_RowValidating event i am validating and preventing user to go to next row. i would like to "mark/color" the cell with the error. I tried all the Style properties but only the forecolor works. (i have commented the lines not working)
So, in addition to RowValidating event, i decided to use the grid2_ViewCellFormatting event to validate and color the cell with the error.
This is working but i dont understand why i have to validate twice. (once in the RowValidating event to prevent them to go to the next row and again in the ViewCellFormatting event to "color" the cell)
Am i doing something wrong? Why am i not able to set the Style Properties directly from within the RowValidating. I am using the Q2 2011 version (latest)
Private Sub grid2_RowValidating(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.RowValidatingEventArgs) Handles grid2.RowValidating If TypeOf e.Row Is GridViewNewRowInfo Or TypeOf e.Row Is GridViewDataRowInfo Then If Not e.Row Is Nothing Then Dim value As String = e.Row.Cells(1).Value If value > 10 Then e.Cancel = True e.Row.Cells(1).ErrorText = "cannot be greater than 10" e.Row.ErrorText = "cannot be greater than 10" e.Row.Cells(1).Style.ForeColor = Color.Red 'These did not work so had to use the cell formating 'e.Row.Cells(1).Style.DrawFill = True 'e.Row.Cells(1).Style.NumberOfColors = 1 'e.Row.Cells(1).Style.BackColor = Color.Peru 'e.Row.Cells(1).Style.DrawBorder = True 'e.Row.Cells(1).Style.BorderWidth = 2 Else e.Row.ErrorText = String.Empty End If End If End IfEnd SubPrivate Sub grid2_ViewCellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles grid2.ViewCellFormatting If grid2.IsInEditMode Then If TypeOf e.Row Is GridViewRowInfo Then Select Case e.ColumnIndex Case 1 e.CellElement.DrawFill = True e.CellElement.NumberOfColors = 1 'validate again?? to set the coloring? If e.CellElement.Value > 10 Then 'set visual clue e.CellElement.BackColor = Color.Peru e.CellElement.ForeColor = Color.Yellow e.CellElement.Image = My.Resources._error Else 'reset all e.CellElement.BackColor = Color.White e.CellElement.ForeColor = Color.Black e.CellElement.Image = Nothing End If End Select End If End IfEnd Sub