We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Can't add a expression field

I am trying to use the examples on the website to add an expression field but it isn't adding it when i run the code

here is the example
ExpressionFieldDescriptor exp1 = new ExpressionFieldDescriptor("Winning %", "([wins] *100)/([wins]+[ties]+[losses])", "System.Double");

ExpressionFieldDescriptor exp1 = new ExpressionFieldDescriptor("Loosing %", "([losses] *100)/([wins]+[ties]+[losses])", "System.Double");



//Adds expression fields to the grid table.

this.gridGroupingControl1.TableDescriptor.ExpressionFields.AddRange(new Syncfusion.Grouping.ExpressionFieldDescriptor[] { exp1, exp2 });

here is my code
ExpressionFieldDescriptor exp1 = new ExpressionFieldDescriptor("Totaal", "[Cost]*2", "System.Double");
          
            this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add(exp1);


can someone please tell me what i am doing wrong


7 Replies

AK Adhikesevan Kothandaraman Syncfusion Team September 9, 2015 12:21 PM UTC

Hi Pierre,

Thank you for using Syncfusion Products.

In the ExpressionFieldDescriptor constructor, we need to pass the columns mapping name that we want to apply the Expression.

Code Example:

//Argument 1: Total is the mapping name of the column which we want to apply the Expression

//Argument 2: Expression like "[Column2] * 2 " Computation with other column values( here "Cost" is another Column name).

ExpressionFieldDescriptor exp1 = new ExpressionFieldDescriptor("Total", "[Cost]*2", "System.Double");

//Adding the expression field to the columns

this.gridGroupingControl1.TableDescriptor.ExpressionFields.Add(exp1);


Sample:

http://www.syncfusion.com/downloads/support/forum/120181/ze/Expression_Fields-1483031551


Regards,

Adhi.



PS Pierre Smith September 9, 2015 02:25 PM UTC

the Cost field i have in my code is the mapping name not the column name

i will try your example and see if it works thank you



AK Adhikesevan Kothandaraman Syncfusion Team September 10, 2015 06:11 AM UTC

Hi Pierre,

We look forward for your response.

Regards,
Adhi.


PS Pierre Smith September 10, 2015 08:50 AM UTC

Ok

So the problem is when i add my own names to the columns by using a columnset and then changing the visible columns then it becomes a problem where the expression field does not want to display. if i take all the columnset and visible columns away and just use it as a raw gridgroupingcontrol then the expression field works fine

so how do i impliment the expression field when i hide some of the columns and when i rename the columns to something different.

do i have to do it in a specific order ?

thank you


VS Venkatesh Sundaram Syncfusion Team September 11, 2015 12:07 PM UTC

Hi Pierre,

Thanks for your interest in Syncfusion Product.

If the columns are hidden and change in the column name will not affect the expression fields. Since, the display text of the column name only changes, where the columns in the hidden state. The expression field are created using the mapping name. Please refer to the following sample for more reference. 

Sample Link:

http://www.syncfusion.com/downloads/support/directtrac/143545/ze/Expression_Fields-706522085

Please let me know if you have any concern.

Regards,
Venkat.



PS Pierre Smith September 21, 2015 08:58 AM UTC

Just an update

The solution you gave me works but I had to figure out why my code is not working
What I discovered is that when I use a GridColumnDescriptorCollection to manually specify the names of my columns you need to add a unbounded column called Total for the expression field
I take it that you use the same name for the Column as what you use for the Expression field is this correct because it seems to work like that.




AK Adhikesevan Kothandaraman Syncfusion Team September 22, 2015 12:51 PM UTC

Hi Pierre,

Thanks for your update.

While adding the expression fields to the TableDescriptor, it will check for the specific field present in the TableDescriptor.Column collection. If the field exist which will apply the expression to that field. Else, it will add a new Field with the expression name. Also, the field which is used for calculating the expression must be visible if you are using the unbound expression field.

Regards,
Adhi

Loader.
Live Chat Icon For mobile
Up arrow icon