After searching the forums for some time (days, well 2 days) I finally have a solution on displaying an Error Icon in a cell of a RADGridView i.e. like in SQL Management Studio when a certain criteria is met.
Scenario 1: Validate all cells in a row simultaneously
Scenario 2: Validate an individual cell
So here goes:
Solution 1: Validate all cells in a row simultaneously
AND TADA : **** THE MAGIC *****
That's it folks. You can use EITHER Solution 1 or 2, but you have to include the magic irrespective of which one you choose.
Hope this saves you some hours.
Sharing is Caring
The_O
Scenario 1: Validate all cells in a row simultaneously
Scenario 2: Validate an individual cell
So here goes:
Solution 1: Validate all cells in a row simultaneously
Private
Sub
rgvSrcExtractFiles_RowValidating(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.RowValidatingEventArgs)
Handles
rgvSrcExtractFiles.RowValidating
If
TypeOf
e.Row
Is
GridViewDataRowInfo
Then
For
Each
cell
As
GridViewCellInfo
In
e.Row.Cells
Select
Case
cell.ColumnInfo.Name
Case
"FileDirectory"
If
Not
FileAcc.DirectoryExists(cell.Value)
Then
cell.ErrorText =
"Directory not found!"
ElseIf
FileAcc.CountFilePrefixWithExt(cell.Value, e.Row.Cells(
"FilePrefix"
).Value, e.Row.Cells(
"FileExtension"
).Value) = 0
Then
cell.ErrorText =
"No valid files found in directory!"
Else
cell.ErrorText =
String
.Empty
End
If
Case
"FilePrefix"
If
FileAcc.CountFilePrefix(e.Row.Cells(
"FileDirectory"
).Value, cell.Value) = 0
Then
cell.ErrorText =
"Files not found!"
Else
cell.ErrorText =
String
.Empty
End
If
Case
"FileExtension"
If
FileAcc.CountFileExt(e.Row.Cells(
"FileDirectory"
).Value, cell.Value) = 0
Then
cell.ErrorText =
"Files not found!"
Else
cell.ErrorText =
String
.Empty
End
If
End
Select
Next
End
If
End
Sub
Solution 2: Validate an individual cell
Private
Sub
rgvSrcExtractFiles_CellValidating(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.CellValidatingEventArgs)
Handles
rgvSrcExtractFiles.CellValidating
Dim
column
As
GridViewDataColumn = TryCast(e.Column, GridViewDataColumn)
If
TypeOf
e.Row
Is
GridViewDataRowInfo
AndAlso
column IsNot
Nothing
Then
Select
Case
column.Name
Case
"FileDirectory"
If
Not
FileAcc.DirectoryExists(e.Value)
Then
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
"Directory not found!"
ElseIf
FileAcc.CountFilePrefixWithExt(e.Value, e.Row.Cells(
"FilePrefix"
).Value, e.Row.Cells(
"FileExtension"
).Value) = 0
Then
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
"Files not found!"
Else
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
String
.Empty
End
If
Case
"FilePrefix"
If
FileAcc.CountFilePrefix(e.Row.Cells(
"FileDirectory"
).Value, e.Value) = 0
Then
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
"Files not found!"
Else
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
String
.Empty
End
If
Case
"FileExtension"
If
FileAcc.CountFileExt(e.Row.Cells(
"FileDirectory"
).Value, e.Value) = 0
Then
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
"Files not found!"
Else
DirectCast
(e.Row.Cells(e.ColumnIndex), GridViewCellInfo).ErrorText =
String
.Empty
End
If
End
Select
End
If
End
Sub
AND TADA : **** THE MAGIC *****
Private
Sub
rgvSrcExtractFiles_CellFormatting(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.CellFormattingEventArgs)
Handles
rgvSrcExtractFiles.CellFormatting
Dim
cell
As
GridDataCellElement = TryCast(e.CellElement, GridDataCellElement)
If
cell IsNot
Nothing
Then
If
cell.ContainsErrors
Then
'Uncomment to draw a red border around cell as well
'cell.DrawBorder = True
'cell.BorderBoxStyle = BorderBoxStyle.SingleBorder
'cell.BorderWidth = 2
'cell.BorderColor = Color.Red
'cell.ImageAlignment = ContentAlignment.MiddleRight
Dim
prov
As
New
ErrorProvider
Dim
conv
As
New
ImageConverter
cell.Image = conv.ConvertFrom(prov.Icon)
cell.TextImageRelation = TextImageRelation.TextBeforeImage
cell.ImageAlignment = ContentAlignment.MiddleRight
cell.ImageLayout = ImageLayout.None
Else
'Resets the borders to the original value
'cell.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local)
'cell.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local)
'cell.ResetValue(LightVisualElement.BorderWidthProperty, ValueResetFlags.Local)
'cell.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local)
cell.Image =
Nothing
End
If
End
If
End
Sub
That's it folks. You can use EITHER Solution 1 or 2, but you have to include the magic irrespective of which one you choose.
Hope this saves you some hours.
Sharing is Caring
The_O