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

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

5 Answers 239 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sagar
Top achievements
Rank 1
Sagar asked on 24 Nov 2010, 08:54 AM
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>

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 24 Nov 2010, 09:00 AM
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
0
Sagar
Top achievements
Rank 1
answered on 24 Nov 2010, 12:02 PM
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:)
0
Maya
Telerik team
answered on 25 Nov 2010, 06:44 PM
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
0
Roland
Top achievements
Rank 1
answered on 20 Dec 2010, 08:13 PM
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.
0
Maya
Telerik team
answered on 21 Dec 2010, 08:51 AM
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
Tags
GridView
Asked by
Sagar
Top achievements
Rank 1
Answers by
Maya
Telerik team
Sagar
Top achievements
Rank 1
Roland
Top achievements
Rank 1
Share this question
or