Support for Regex Validation in Grid Columns

This commit is contained in:
Jonathan Jenne
2021-10-01 15:00:42 +02:00
parent 03e87efedc
commit 75d1ceb3de
3 changed files with 27 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
Imports System.ComponentModel
Imports System.Text.RegularExpressions
Imports DD_LIB_Standards
Imports DevExpress.Utils
Imports DevExpress.XtraEditors
@@ -584,10 +585,30 @@ Public Class ClassControlCreator
Dim oIsRequired = oColumn.Item("VALIDATION")
Dim oValue = NotNull(oView.GetRowCellValue(e.RowHandle, oCol.ColumnName), "")
Try
Dim oRegex = NotNull(oColumn.Item("REGEX_MATCH"), String.Empty)
Dim oRegexMessage = NotNull(oColumn.Item("REGEX_MESSAGE_DE"), String.Empty)
If oRegex <> String.Empty Then
Dim oMatch = New Regex(oRegex).IsMatch(oValue)
Dim oDefaultMessage = "Wert entspricht nicht dem gefordertem Format!"
Dim oMessage = IIf(oRegexMessage <> String.Empty, oRegexMessage, oDefaultMessage)
If oMatch = False Then
oView.SetColumnError(oGridColumn, oMessage)
e.Valid = False
Exit For
End If
End If
Catch ex As Exception
LOGGER.Error(ex)
End Try
If oIsRequired And oValue = "" Then
oView.SetColumnError(oGridColumn, "Spalte muss ausgefüllt werden!")
e.Valid = False
Exit For
End If
Next
End Sub