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
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?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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.
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.
expression column just stays empty
have you some example on that when datatable is source for gridview?!
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.
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!!!!
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.
row["Price1"] = 2.5;
row["Price2"] = 0.5;
or
row["Price1"] = Convert.ToDecimal("2,5");
row["Price2"] = Convert.ToDecimal("0,5");
but no luck :(
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 .
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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.
thank you.