ExpressionEditor bound value not updating?

3 posts, 0 answers
  1. Raoul
    Raoul avatar
    36 posts
    Member since:
    Apr 2012

    Posted 20 Jan 2014 Link to this post

    Hello Telerik support,

    I hav a grid which binds an (Telerik Open Access) object source. Some columns have Expression Editors:

    //  Attaching the datasource
    radGridView2.DataSource = _activeBatch.LigdagenKlinischGefactureerds.OrderBy(c => c.RowNumber);
    // Expression column definition:
    GridViewTextBoxColumn b = new GridViewTextBoxColumn("B")
                    HeaderText = "B",
                    EnableExpressionEditor = true,               
                    Expression = @"IIF(ISNULL(PreviousNo,"""")<>No,""nieuw"",null)"

    When saving the datasource something strange happens. Just before do a SaveChanges I check the values of a specific row which should contain changed (evaluated) values:

    radGridView2.Row[x].Cell["B"].Value = "nieuw", this is as expected for the evaluation of row X
    (radGridView2.Row[x].DataBoundItem as MyBoundObject).B = null (???)

    Additionally I have another question: If my datasource contains a value, the expression should not be evaluated. Is this possible? (maybe on a specific cell event?)

    Kind regards,

  2. Raoul
    Raoul avatar
    36 posts
    Member since:
    Apr 2012

    Posted 21 Jan 2014 Link to this post

    I managed to figure out a part of the solution. Long story short: After binding the grid I iterate the rows, updating the databounditem with the cell value using reflection (cell.column fieldname = name):

    void radGridView2_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
                if (radGridView2.Rows.Count > 0)
                    var expresionCols = radGridView2.Rows[0].Cells.Cast<GridViewCellInfo>().Where(x => !String.IsNullOrEmpty(x.ColumnInfo.Expression));
                    foreach (GridViewRowInfo row in radGridView2.Rows)
                        MyDataboundItem ligdag = row.DataBoundItem as MyDataboundItem 
                        foreach (GridViewCellInfo cell in expresionCols)
                           PropertyInfo prop = (typeof(MyDataboundItem)).GetProperty(cell.ColumnInfo.Name);
                           prop.SetValue(ligdag, row.Cells[cell.ColumnInfo.Name].Value, null);
                           _ctx.MakeDirty(ligdag, cell.ColumnInfo.Name);

    Now on saving, the calculated (expression result) values are stored in the database.

    I'd still would like the option to edit the cell (-value) of the expression result. Somehow the cells in a column with an expression seem to be readonly... 

  3. George
    George avatar
    500 posts

    Posted 23 Jan 2014 Link to this post

    Hello Raoul,

    Thank you for contacting us.

    There are two possible reasons here.

    First, you should bind RadGridView to a list instead to the result of a lambda expression. A guide which shows how to bind RadGridView with OpenAccess can be found here.

    The second reason is that the expression seems to be invalid. I tried to build it with our ExpressionEditor, however it was not recognized as a valid expression. Also I am not sure what is its purpose and what is the structure of your data source. I suggest to you to first try to build the expression using the ExpressionBuilder, and then set that expression.

    If you need further assistance, please provide me with some additional details about your project and any information which may be of help.

    Let me know how this works out.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top