Databinding and producing a SUM value

4 posts, 0 answers
  1. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 13 Sep 2010 Link to this post

    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
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 15 Sep 2010 Link to this post

    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
  3. DevCraft banner
  4. madladuk
    madladuk avatar
    126 posts
    Member since:
    Dec 2009

    Posted 16 Sep 2010 Link to this post

    Hi, is it possible to provide me a sample peice of code. I am using entitfy framework not mvm

    Thanks
    P
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 20 Sep 2010 Link to this post

    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
Back to Top