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

Expression Columns

12 Answers 216 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dalibor
Top achievements
Rank 1
Dalibor asked on 06 Mar 2013, 11:24 AM
hi,

i have problem with refreshing column data when using expressions. My gridview is bind to datatable. 

example:

Datatable has column 1 and column2
  
column 1,
column 2,
...
expression column
expression = "column1+column2"

Is there any way to rebind or refresh expression? My datatable is dynamically filled with data.

mygrid.itemsSource=datatable.defaultView

12 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 06 Mar 2013, 01:17 PM
Hello,

Would you please share how do you change the values in column1 and column2? Do you do this from the UI or from code behind?
 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dalibor
Top achievements
Rank 1
answered on 06 Mar 2013, 02:20 PM

values are changing from datatable, insert, delete rows or direct change in datatable on Column1, Column2, etc...

Binding refresh values in GridView.

this is done in code behind.

 

 

 

0
Dimitrina
Telerik team
answered on 06 Mar 2013, 04:07 PM
Hello,

You could invoke a Rebind() for the GridView and the values in the ExpressionColumn will be refreshed.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dalibor
Top achievements
Rank 1
answered on 06 Mar 2013, 10:02 PM
i have tried that, not working!
expression column just stays empty

have you some example on that when datatable is source for gridview?!
0
Vlad
Telerik team
answered on 07 Mar 2013, 06:57 AM
Hello,

 Please open support ticket and send us small example project demonstrating your scenario and the actual problem.

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dalibor
Top achievements
Rank 1
answered on 07 Mar 2013, 08:07 AM

XAML
<telerik:RadGridView AutoGenerateColumns="False"
                                         CanUserInsertRows="False" HorizontalAlignment="Stretch"
                                         IsFilteringAllowed="False"
                                         IsHitTestVisible="True"
                                         IsReadOnly="True"
                                         ItemsSource="{Binding Path=dataTable}"
                                         MinHeight="250"
                                         Name="radGridView" >
                                        
                        <telerik:RadGridView.Columns>
                            <custom:MyColumn Header="Rbr" Width="30" />
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Price1}" Header="Price1" MinWidth="70" IsReadOnly="True" />
       <telerik:GridViewExpressionColumn Expression="Price1 + Price2"  DataFormatString="{}{0:C}" Header="SumPrice" UniqueName="SumPrice" HeaderTextAlignment="Right" MinWidth="80" TextAlignment="Right"  />
<telerik:RadGridView />

code in some function that writes data.

DataRow row = this.dataTable.NewRow();

row["Price1"] = "2,36";
row["Price2"] = "0,5";

this.dataTable.Rows.Add(row);

this.radGridView.Rebind(); // but not working!!!!

0
Vlad
Telerik team
answered on 07 Mar 2013, 08:36 AM
Hi,

 According to your code you have strings. You cannot sum strings - only numeric values. 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dalibor
Top achievements
Rank 1
answered on 07 Mar 2013, 12:04 PM
i have also tried
 
row["Price1"] = 2.5;
row["Price2"] = 0.5;

or
 
row["Price1"] = Convert.ToDecimal("2,5");
row["Price2"] = Convert.ToDecimal("0,5");

but no luck :(
0
Dimitrina
Telerik team
answered on 07 Mar 2013, 12:08 PM
Hello,

Would it be possible for you to isolate the issue in a demo project which we could debug locally? You can take a look at this blog post on how to isolate a problem in a sample project .

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dalibor
Top achievements
Rank 1
answered on 07 Mar 2013, 01:32 PM
i have uploaded litle demo example

http://snk.to/f-cu9lrl8p
0
Dimitrina
Telerik team
answered on 07 Mar 2013, 02:12 PM
Hello,

As my colleague said you should sum numeric values. In your case the value

this.dataTable.Rows[0]["Price1"] 
is an object, not a decimal. The same applies for Price2.

In order to have the expression calculated, you can set it for the column like so:
Expression<Func<DataRowView, decimal>> expression = prod => Convert.ToDecimal(prod["Price1"]) * 2;
GridViewExpressionColumn expColumn = this.radGridView.Columns["Sum Price"] as GridViewExpressionColumn;
expColumn.Expression = expression;


I hope this helps.

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dalibor
Top achievements
Rank 1
answered on 08 Mar 2013, 06:27 AM
this is working great.

thank you.
Tags
GridView
Asked by
Dalibor
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Dalibor
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or