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

ExpressionEditor bound value not updating?

2 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raoul
Top achievements
Rank 1
Raoul asked on 20 Jan 2014, 06:09 PM
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,
Raoul

2 Answers, 1 is accepted

Sort by
0
Raoul
Top achievements
Rank 1
answered on 21 Jan 2014, 05:26 PM
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 = databaounditem.property 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);
                    }
                    row.InvalidateRow();
                }
            }
        }

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... 

Regards,
Raoul
0
George
Telerik team
answered on 23 Jan 2014, 01:45 PM
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.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
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 >>
Tags
GridView
Asked by
Raoul
Top achievements
Rank 1
Answers by
Raoul
Top achievements
Rank 1
George
Telerik team
Share this question
or