The Cross-Platform Class Library provides criteria language that you can use in various DevExpress products for building expressions. An expression is a string that, when parsed using the CriteriaOperator.Parse method to a CriteriaOperator object, evaluates some value. The table below contains constants, operators, and functions you can use in expressions.
The following DevExpress products extend and/or override this syntax. The table below lists the articles that explain how to use expressions in these products.
Specify different numeric constant types in a string form using suffixes:
Int32 (int) - 1
Int16 (short) - 1s
Byte (byte) - 1b
Double (double) - 1.0
Single (float) - 1.0f
Decimal (decimal) - 1.0m
[Price] == 25.0m
Represents a null reference that does not refer to any object.
We recommend using the IsNull unary operator (for example, "[Region] is null") or the IsNull logical function (for example, "IsNull([Region])") instead.
[Region] != ?
You can build parameterized criteria using any number of positional parameters. To do this, add parameter placeholders (question mark characters) to a criteria expression to identify parameter positions and provide a list of parameter values. When building criteria, parameter placeholders are substituted with parameter values in values in the order they are listed.
CriteriaOperator.Parse("[Name] == ? and [Age] == ?", "John", 33)
The following two examples are identical, but the second one allows you to avoid formatting errors.
Adds the value of one numeric expression to another or concatenates two strings.
[UnitPrice] + 4
[FirstName] + ' ' + [LastName]
Finds the difference between two numbers.
[Price1] - [Price2]
Multiplies the value of two expressions.
[Quantity] * [UnitPrice] * (1 - [BonusAmount])
Divides the first operand by the second.
[Quantity] / 2
Returns the remainder (modulus) obtained by dividing one numeric expression by another.
[Quantity] % 3
Performs a bitwise inclusive OR on two numeric expressions. Compares each bit of its first operand to the corresponding bit of its second operand. If either bit is 1, the corresponding resulting bit is set to 1. Otherwise, the corresponding resulting bit is set to 0.
[Number] | [Number]
The bitwise AND operator. Compares each bit of its first operand to the corresponding bit of its second operand. If both bits are 1, the corresponding resulting bit is set to 1. Otherwise, the corresponding resulting bit is set to 0.
[Number] & 10
Performs a bitwise exclusive OR on two numeric expressions.
[Number] ^ [Number]
Returns true if both operands have the same value; otherwise, it returns false.
[Quantity] == 10
Returns true if the operands do not have the same value; otherwise, it returns false.
[Country] != 'France'
Less than operator. Used to compare expressions.
[UnitPrice] < 20
Less than or equal to operator. Used to compare expressions.
[UnitPrice] <= 20
Greater than or equal to operator. Used to compare expressions.
[UnitPrice] >= 30
Greater than operator. Used to compare expressions.
[UnitPrice] > 30
Tests for the existence of a property in an object.
[Country] In ('USA', 'UK', 'Italy')
Specifies a range to test. Returns true if a value is greater than or equal to the first operand and less than or equal to the second operand.
[Quantity] Between (10, 20)
Performs a logical conjunction on two Boolean expressions.
[InStock] And ([ExtendedPrice]> 100)
[InStock] && ([ExtendedPrice]> 100)
Performs a logical disjunction on two Boolean expressions.
[Country]=='USA' Or [Country]=='UK'
[Country]=='USA' || [Country]=='UK'
Performs a bitwise negation on a numeric expression.
~[Roles] = 251
Performs a logical negation on a Boolean expression.
Returns a numeric expression's value (a unary operator).
+[Value] = 10
Returns the negative of a numeric expression's value (a unary operator).
-[Value] = 20
Returns true if an expression is a null reference, the one that does not refer to any object.
Evaluates the average of the values in the collection.
Returns the number of objects in a collection.
Determines whether the object exists in the collection.
[Categories][[CategoryID] == 7].Exists()
Returns the maximum expression value in a collection.
Returns the minimum expression value in a collection.
Returns a single object from a collection that contains no more than one object.
If the collection contains more objects, use the Condition property to specify a condition. The collection must contain only one object that satisfies the condition; otherwise, the function's behavior is undefined (the function may return an unexpected value or throw an exception).
You can pass an expression as a parameter: [Collection][Condition].Single(Expression).
The function returns the Expression value evaluated on an object that meets the specified Condition (optional).
[Accounts].Single() is not null
[Collection].Single([Property1]) - returns the found object's property value.
Returns the sum of all the expression values in the collection.
A custom aggregate function
Returns a custom expression value for a collection, according to a custom aggregate function.
You can call the function directly or pass it as a parameter.
Returns the ASCII code value of the leftmost character in a character expression.
Converts an integerASCIICode to a character.
Char(65) + Char(51)
Returns the starting position of String1 within String2, beginning from the zero character position to the end of a string.
CharIndex(String1, String2, StartLocation)
Returns the starting position of String1 within String2, beginning from the StartLocation character position to the end of a string.
CharIndex('e', 'devexpress', 2)
Concat(String1, ... , StringN)
Returns a string value containing the concatenation of the current string with any additional strings.
Concat('A', ')', [ProductName])
Returns True if SubString1 occurs within String1; otherwise, False is returned.
Returns True if the end of String1 matches SubString1; otherwise, False is returned.
EndsWith([Description], 'The end.')
Insert(String1, StartPosition, String2)
Inserts String2 into String1 at the position specified by StartPositon
Insert([Name], 0, 'ABC-')
Returns an integer containing either the number of characters in a string or the nominal number of bytes required to store a variable.
Returns String in lowercase.
Left-aligns the defined string's characters, padding its left side with white space characters up to a specified total length.
PadLeft(String, Length, Char)
Left-aligns the defined string's characters, padding its left side with the specified Char up to a specified total length.
PadLeft([Name], 30, '<')
Right-aligns the defined string’s characters, padding its left side with empty space characters up to a specified total length.
PadRight(String, Length, Char)
Right-aligns the defined string’s characters, padding its left side with the specified Char up to a specified total length.
PadRight([Name], 30, '>')
Deletes all the characters from this instance, beginning at a specified position.
Remove(String, StartPosition, Length)
Deletes a specified number of characters from this instance, beginning at a specified position.
Remove([Name], 0, 3)
Replace(String, SubString2, String3)
Returns a copy of String1, in which SubString2 has been replaced with String3.
Replace([Name], 'The ', '')
Reverses the order of elements within String.
Returns True if the beginning of String1 matches SubString1; otherwise, False.
StartsWith([Title], 'The best')
Substring(String, StartPosition, Length)
Retrieves a substring from String. The substring starts at StartPosition and has a specified Length.
Substring([Description], 2, 3)
Retrieves a substring from String. The substring starts at StartPosition.
Returns a string representation of an object.
Removes all leading and trailing SPACE characters from String.
Returns String in uppercase.
You can find a complete set of available function operators in the FunctionOperatorType enumeration description.
Collection Elements Verification
Use brackets "" to check if a collection contains an element that satisfies a condition. The following expression returns true if the Accounts collection contains at least one element that satisfies the [Amount] == 100 condition:
[Accounts][[Amount] == 100]
The following expression returns false if the Accounts collection is empty:
Parent Relating Operator
Use the parent relating operator ('^' character) to refer to a parent in expressions written in the context of a child. You can apply this operator successively to navigate multiple parent relationships. In the expression below, the "RegistrationDate" field refers to a Customer (Orders' parent) and the "Date" field refers to Orders. This expression returns true if there is at least one Order that is made on the day the parent Customer is registered:
"[Orders][[^.RegistrationDate] == Date]"
Grouping Clauses with Brackets
It is important to use brackets to ensure that your expression returns the intended results.
For instance, the following expression for objects of the Customer type returns all of the Customers where an Account exists with a Date of 8/25/2006 and where an account exists with an Amount of 100:
When an expression contains multiple operators, their precedence controls the order in which expression elements are evaluated.
'.' relationship qualifier (left-associative)
<, >, <=, >=
-, + (left-associative)
*, /, % (left-associative)
Trim(), Len(), Substring(), IsNull()
'' (for set-restriction)
The default precedence can be changed by grouping elements with parentheses. For instance, the operators are performed in a default order in the first of the following two code samples. In the second code sample, the addition operation is performed first, because its associated elements are grouped with parentheses, and the multiplication operation is performed last.
Accounts[Amount == 2 + 48 * 2]
Accounts[Amount == (2 + 48) * 2]
Operators are case insensitive. Although field values’ case sensitivity depends on the data source.
A data source affects certain operators' behavior. For instance, by default, the SQL Server Express 2005 is configured as case insensitive. In this case, the following expression always evaluates to true:
Lower(Name) == Upper(Name)
You can mark a keyword-like field name with an escape character (@ sign). In the expression below, the CriteriaOperator.Parse method interprets @Or as the field named "Or", not the logical operator OR.
@Or = 'value'
Use a backslash (\) as an escape character for characters in expressions. Examples:
Retrieving Reference Properties
Note that while a criteria expression can return an object reference, this is not supported in all scenarios. Returning an object reference by directly referencing a property, as in the following code snippet, is fully supported.
"Iif(Part is null, MyCustOrderLine.Part, Part)"
In this code snippet, the Part object, which the Part or MyCustOrderLine.Part property references, is returned correctly. However, retrieving reference properties from functions is not supported. So, the following expression does not work.
"Iif(Part is null, MyCustOrderLine, MyCustOrderLine2).Part"
Note - Restrictions
Note the following restriction when exporting DevExpress Data Grid and Tree List controls (WinForms and WPF) to the XLS(X) format in Data-Aware Export Mode:
Only expressions that contain export-friendly functions are exported to XLS(X) format. Refer to the XLS(x) Format Export-Friendly column in the tables above to find out if a function can be exported to XLS(x) format.