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

How to make expression column calculate based on the current visible columns


I have a situation like this. I have three columns (A, B, and C) and a expression columns that is defines as A + B + C.

expr-----colA---colB---colC
60 ----- 10 --- 20 --- 30

when the visible columns is colA and colC, I want the expression column to calculate based on only columns A and C like below

expr-----colA---colC
40 ----- 10 --- 30


Is there a way to do this? I am trying to achieve something like the RecordFilter, but only apply that to columns.

4 Replies

AD Administrator Syncfusion Team December 7, 2006 06:11 AM UTC

Hi James,

You can handle the VisibleColumn.Changing event and set the ExpressionDescriptor.Express property to your required expression. Here is a code snippet to show this.

private void VisibleColumns_Changing(object sender, Syncfusion.Collections.ListPropertyChangedEventArgs e)
{
if( e.Action == Syncfusion.Collections.ListPropertyChangedType.Add)
{
ExpressionFieldDescriptor ed = this.gridGroupingControl1.TableDescriptor.ExpressionFields["ExpressionColumn"];
GridVisibleColumnDescriptor column = e.Item as GridVisibleColumnDescriptor;
if( ed.Expression.IndexOf(column.Name) == -1)
{
string sOldValue = string.Format("+ [{0}]",column.Name);
ed.Expression += sOldValue;
}
}
else if( e.Action == Syncfusion.Collections.ListPropertyChangedType.Remove)
{
ExpressionFieldDescriptor ed = this.gridGroupingControl1.TableDescriptor.ExpressionFields["ExpressionColumn"];
GridVisibleColumnDescriptor column = e.Item as GridVisibleColumnDescriptor;
if( ed.Expression.IndexOf(column.Name) != -1)
{
string sOldValue = string.Format("+ [{0}]",column.Name);
string Expression = ed.Expression.Replace(sOldValue,string.Empty);
if( Expression.Equals(ed.Expression) )
{
Expression = ed.Expression.Replace(string.Format("[{0}] +",column.Name),string.Empty);
}
ed.Expression = Expression;
}
}
}

Here is a sample.
GGCExpressionField.zip

Best Regards,
Haneef


JB James Blibo December 7, 2006 06:21 AM UTC

Are you kidding me? I was about to create different permutations of expression fields to accomplish the same thing. You guys are the greatest!

thx


JB James Blibo March 4, 2007 06:47 PM UTC

I have a couple of summary columns above the header. When I toggle (show/hide) soecific visible columns, I expect the summary column above each specific visible columns to also show/hide, depending on which visible columns they're align to; however, this is not happening... what gives?


JB James Blibo March 5, 2007 03:31 AM UTC

got it to work... please disregard post

Loader.
Live Chat Icon For mobile
Up arrow icon