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

2q2009 create Footer row using code

3 Answers 115 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erez
Top achievements
Rank 1
Erez asked on 09 Jul 2009, 04:43 PM
Hello,

I am trying to create a totals row using code.
I saw the Totals example using XAML and also found the following post:
http://www.telerik.com/community/forums/wpf/gridview/2q2-9-radgridview-footer-row-sample-question.aspx
however I got stuck. No value is displayed in the Totals row.

Thanks,

Erez


<Window x:Class="TestTelerikQ2.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
    Title="Window1" Height="378" Width="536">
    <Grid>
        <StackPanel Orientation="Vertical">
            <telerik:RadGridView Margin="12,20,-12,-20"
                                Name="radGridView1"
                                Loaded="radGridView1_Loaded"
    ShowColumnFooters="True" AutoGenerateColumns="False" >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn  UniqueName="Number"
       DataMemberBinding="{Binding Number}">
                    </telerik:GridViewDataColumn>
                </telerik:RadGridView.Columns>
               
            </telerik:RadGridView>
        </StackPanel>
    </Grid>
</Window>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Data;

namespace TestTelerikQ2
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            try
            {
                InitializeComponent();

                GridViewFooterCell g;
               
                GridViewFooterRow footerRow = new GridViewFooterRow();

                Telerik.Windows.Data.SumFunction sum = new SumFunction();

                sum.Caption = "sum: ";

 

                sum.ResultFormatString = "{}{0:c}";

                sum.SourceField = "Number";

                Telerik.Windows.Controls.GridViewDataColumn column =
                        (Telerik.Windows.Controls.GridViewDataColumn)radGridView1.Columns["Number"];

               

                //column.Footer = footerRow;

                DataTable dt = new DataTable();
                DataView dv;

                dt.Columns.Add("Display", typeof(string));
                dt.Columns.Add("Number", typeof(int));

                dt.Rows.Add("show", 1);
                dt.Rows.Add("show", 2);
                dt.Rows.Add("hide", 3);

                dv = new DataView(dt);

 

                radGridView1.ItemsSource = dv;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }

                       
        }

    }
}

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 10 Jul 2009, 05:17 AM
Hi Erez,

Please check this demo for more info:
http://demos.telerik.com/wpf/?GridView/Totals

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Erez
Top achievements
Rank 1
answered on 20 Jul 2009, 03:00 PM
Hi Vlad,

I examined the example, however it do not suit my needs.

I cannot use the default aggregation functions and need to access the footer row and change the values in its cells "by hand".

 


So far, I came up with the following code:

string sDataColName = "col_name";
int iColIndex = 0;

var rows = RadGridView1.ChildrenOfType<GridViewFooterRow>();
GridViewFooterRow oFootRow = rows[0];

First way:

GridViewFooterCell oCell = (GridViewFooterCell)oFootRow.Cells[iColIndex];

Second way:

GridViewFooterCell oCell = (GridViewFooterCell)oFootRow.Cells.Where(
                                                            c => ((c as GridViewFooterCell) != null
                                                           && ((GridViewFooterCell)c).PropertyName == sDataColName)).FirstOrDefault();

if (oCell != null)
{
  oCell.Content = "text text text" ;
}




Is there a quicker way I can access cells in the footer row by their column name ?

Thanks,

Erez


0
Accepted
Stefan Dobrev
Telerik team
answered on 23 Jul 2009, 07:30 AM
Hi Erez,

We currently did not provide any methods for accessing those elements. What you have currently implemented is the easiest way to achieve this.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Erez
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Erez
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Share this question
or