Create Standalone RadExpressionEditor Form
Date Posted | Product | Author |
---|---|---|
09/09/2013 | UI for WinForms | Georgi Georgiev |
Problem
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:
As the static/shared constructor is called before the instance of the form is created it will guarantee us that the grid and its column are initialized.
A sample usage of this class so far would look like this:
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:
As the result is stored in the dummy row, we can just take its value and use it:
And now our form should be ready to use. Using it can be limited to only 5 lines of code:
A complete solution in C# and VB.NET can be found here.