This is a migrated thread and some comments may be shown as answers.

Cell formatting/expression editor

1 Answer 98 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chom
Top achievements
Rank 1
Chom asked on 18 Feb 2014, 06:47 PM
Hello,

I am trying to format a cell. I am returning a Boolean value and instead of displaying a true or false in the cell I want to display a 1 for true and a 0 for false. I have this in the cell formatting event and I have two columns, the first returns the true/false value which I am reading and then displaying the 1,0 in another column. It works fin when the true/false column is visible but when I hide it I do not see the 1,0 in the other column.

Here is what I have:
​ //Cell formatting for start bit visual indication. The Start column has been hidden.
if (e.CellElement.ColumnInfo.HeaderText == "Start")
{
if ((bool)e.CellElement.RowInfo.Cells["Start"].Value == true)
{
e.CellElement.RowInfo.Cells["StartBit"].Value = "1";
}
else
{
e.CellElement.RowInfo.Cells["StartBit"].Value = "0";
}
}


Can this be done in the expression editor for the true/false column or what is the best way to achieve this.

Thank you,

chom

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 Feb 2014, 01:37 PM
Hi Chom,

Thank you for contacting us.

In this case you can indeed use the expression editor. You can create a custom function and return the appropriate value.

First you can create a custom ExpressionContext class:
public class CustomExpressionContext : Telerik.Data.Expressions.ExpressionContext
{
    public string GetVal(bool col2Value)
    {
        return col2Value == true ? "0" : "1";
    }
}

Then you can use it to set the values:
Telerik.Data.Expressions.ExpressionContext.Context = new CustomExpressionContext();
col1.EnableExpressionEditor = true;
col1.Expression = "GETVAL(col2)";//col2 in the name of your invisible column

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Telerik
Tags
GridView
Asked by
Chom
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or