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

Databinding and producing a SUM value

3 Answers 67 Views
Gauge
This is a migrated thread and some comments may be shown as answers.
madladuk
Top achievements
Rank 2
madladuk asked on 13 Sep 2010, 11:06 AM
I have an enetity set on a page linked to a gridview showing a list of holidays. I also have a gauge on the same page. I want to be able to bind the gauge to the same datasource/datacontext and produce a show a SUM value of all the holidays. Therefore as they add new holidays to the grid the gauge would then increase/decrease its value. I have seen how you can bind it to a value but not to take an entity set and produce the SUM value. Thanks P

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 15 Sep 2010, 02:55 PM
Hello Paul,

You can use additional property for your entity set implementation to bind it to an indicator's value of the gauge.
The get method of the property should calculate the SUM value of all the holidays. Also you should implement the INotifyPropertyChanged interface and use event like CollectionChanged to call the PropertyChanged event handler for this property.

All the best,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
madladuk
Top achievements
Rank 2
answered on 16 Sep 2010, 12:08 PM
Hi, is it possible to provide me a sample peice of code. I am using entitfy framework not mvm

Thanks
P
0
Andrey
Telerik team
answered on 20 Sep 2010, 04:46 PM
Hi madladuk,

There is very elegant way to implement your scenario just using functionality provided by RadGridView. It allows binding to the aggregate functions defined for grid column. For example:

<UserControl x:Class="RadGridView.Silverlight.BindToAggregate.MainPage"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:local="clr-namespace:RadGridView.Silverlight.BindToAggregate"
             Width="500" Height="400">
    <UserControl.Resources>
        <local:IntToDoubleConverter x:Key="IntToDoubleConverter" />
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <telerik:RadGauge Width="200" Height="200">
            <telerik:RadialGauge>
                <telerik:RadialScale Min="0" Max="100">
                    <telerik:IndicatorList>
                        <telerik:Needle Value="{Binding AggregateResults[\HolidaySum\].Value, ElementName=RadGridView1, Converter={StaticResource IntToDoubleConverter}}" 
                            ValueChanged="NeedleValueChanged"/>
                    </telerik:IndicatorList>
                </telerik:RadialScale>
            </telerik:RadialGauge>
        </telerik:RadGauge>
        <telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}" Grid.Row="1" AutoGenerateColumns="False" >
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Holidays}">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction FunctionName="HolidaySum" SourceField="Holidays" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </Grid>
</UserControl>

In this scenario I’ve supposed that number of the holidays is integer value, so we need int-to-double converter applied to the needle value binding.

Kind regards,
Andrey Murzov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Gauge
Asked by
madladuk
Top achievements
Rank 2
Answers by
Andrey
Telerik team
madladuk
Top achievements
Rank 2
Share this question
or