Expression Columns

13 posts, 0 answers
  1. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 06 Mar 2013 Link to this post

    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

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Mar 2013 Link to this post

    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.

  3. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 06 Mar 2013 Link to this post

    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.

     

     

     

  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Mar 2013 Link to this post

    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.

  5. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 06 Mar 2013 Link to this post

    i have tried that, not working!
    expression column just stays empty

    have you some example on that when datatable is source for gridview?!
  6. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Mar 2013 Link to this post

    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.

  7. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 07 Mar 2013 Link to this post

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

  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 07 Mar 2013 Link to this post

    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.

  9. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 07 Mar 2013 Link to this post

    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 :(
  10. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Mar 2013 Link to this post

    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.

  11. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 07 Mar 2013 Link to this post

    i have uploaded litle demo example

    http://snk.to/f-cu9lrl8p
  12. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 07 Mar 2013 Link to this post

    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.

  13. Dalibor
    Dalibor avatar
    10 posts
    Member since:
    Mar 2013

    Posted 08 Mar 2013 Link to this post

    this is working great.

    thank you.
Back to Top