Bind Aggregate value of column to another control(text box)

6 posts, 0 answers
  1. Sagar
    Sagar avatar
    17 posts
    Member since:
    Sep 2010

    Posted 24 Nov 2010 Link to this post

    I'm using AggregateFunction in my radgrid for several columns.I want to bind those aggregated values to different text boxes also.I don't know how to do it.
    One of my column code is as below.I need to bind Aggregate value of NetSales field to textbox.


    <telerik:GridViewDataColumn Header="NetSale" TextWrapping="Wrap" IsReadOnly="True"  DataMemberBinding="{Binding NetSales}">
                            <telerik:GridViewDataColumn.AggregateFunctions>
                                <telerik:SumFunction Caption="Sum: " ResultFormatString="{}{0:f}" SourceField="NetSales" />
                            </telerik:GridViewDataColumn.AggregateFunctions>

                            <telerik:GridViewDataColumn.Footer>
                                <StackPanel Orientation="Vertical" Margin="5,0">
                                    <!--<TextBlock Text="Custom footer with aggregates:" Margin="0,0,0,2" />-->
                                    <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center" Grid.Column="5">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                                    <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                        <ItemsControl.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Vertical" />
                                            </ItemsPanelTemplate>
                                        </ItemsControl.ItemsPanel>
                                    </telerik:AggregateResultsList>
                                </StackPanel>
                            </telerik:GridViewDataColumn.Footer>
                            <telerik:GridViewDataColumn.GroupFooterTemplate>
                                <DataTemplate>

                                    <StackPanel Orientation="Vertical" Margin="5,0">
                                        <!--<TextBlock Text="Custom footer with aggregates:" Margin="0,0,0,2" />-->
                                        <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center" Grid.Column="5">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                                        <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                                                    </StackPanel>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                            <ItemsControl.ItemsPanel>
                                                <ItemsPanelTemplate>
                                                    <StackPanel Orientation="Vertical" />
                                                </ItemsPanelTemplate>
                                            </ItemsControl.ItemsPanel>
                                        </telerik:AggregateResultsList>
                                    </StackPanel>
                                </DataTemplate>
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 24 Nov 2010 Link to this post

    Hello Sagar,

    Each column keeps a collection of its aggregate functions. So, using the Columns collection of the RadGridView, you may find the desired column, take its aggregates and bind them to the Text property of the TextBox you want. 

    Regards,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  3. DevCraft banner
  4. Sagar
    Sagar avatar
    17 posts
    Member since:
    Sep 2010

    Posted 24 Nov 2010 Link to this post

    Hi Maya,
    Can we bind text property of textbox in this way -
     Text="{Binding DataGridView1,Path=AggregateResults[3].FormattedValue,FallbackValue=0.00}"
    I want to bind it in design,as my radgrid is editable so aggregate changes accordingly so I want to change text of textbox too.

    Got it.
    There was some syntactical error:)
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 25 Nov 2010 Link to this post

    Hi Sagar,

    Unfortunately, it is not possible to do the binding in such a way. You may define the Name of the TextBox:

    <TextBox x:Name="textBox" />
    reference it in the code-behind and set its Text property to be the aggregate result of the column you want.

    Kind regards,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  6. Roland
    Roland avatar
    1 posts
    Member since:
    Dec 2010

    Posted 20 Dec 2010 Link to this post

    My grid is editable. I am seting initial vallue of my textbox to aggreggate value in DataLoaded event handler of a grid. The problem is that after user changes the cell value I need to update my textbox with a new aggregated value. I tried to do it in cell edit end event but the aggrgate value is not updated at that point. What event I should add my update logic to? Looking for something like aggregate values recalculated.
  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 21 Dec 2010 Link to this post

    Hello Roland,

    Basically, the method for recalculating the aggregates is CalculateAggregates():

    this.clubsGrid.CalculateAggregates();

    Furthermore, you may take a look at this forum thread for a reference and a sample project on a similar topic to yours.

    All the best,
    Maya
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
Back to Top
DevCraft banner