Create Standalone RadExpressionEditor Form

You need to allow your users to use expressions such as Max(), Average(),Len() etc.

SOLUTION
Create a standalone RadExpressionEditor Form which will work without you needing to display an actual RadGridView:

The main goal of this standalone form is to allow us to pass it whatever text we need and get the result after closing it. For this we will need to create our own ExpressionEditor form which derives from RadExpressionEditorForm:

Now you can even customize the form’s look and feel in design time to fit your needs.

Usually the RadExpressionEditorForm requires a RadGridView in order to work. That is why we will need to simulate that. We can avoid the manual creation of the grid by initializing it in the static/shared constructor:

So far, so good. We have a form which can work with expressions without a grid to worry about.

Now we just need to be able to pass it an expression when showing it and receiving the result when it is being closed. As we are going to use the ShowDialog method, what we can do is create our own ShowDialog method and pass that expression as an argument:

C#

publicDialogResult ShowDialog(objectinitialValue)

{

this.Expression = initialValue.ToString();

returnbase.ShowDialog();

}

VB

PublicFunctionShowDialog(initialValue AsObject) AsDialogResult

Me.Expression = initialValue.ToString()

ReturnMyBase.ShowDialog()

EndFunction

As the result is stored in the dummy row, we can just take its value and use it:

C#

publicstringReturnValue

{

get

{

returnhiddenGrid.Rows[0].Cells[0].Value.ToString();

}

}

VB

PublicReadOnlyPropertyReturnValue() AsString

Get

ReturnhiddenGrid.Rows(0).Cells(0).Value.ToString()

EndGet

EndProperty

And now our form should be ready to use. Using it can be limited to only 5 lines of code:

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.