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

Deleting Columns Messes up Row Footers

5 Answers 40 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 2
Aaron asked on 28 Aug 2012, 02:40 PM
I'm building a timesheet application.  The timesheet periods are variable in length.  If the timesheet is for the first half of the month (1st through the 15th), then there are 15 date columns.  If it's for the second half of the month, then there could be 13 - 16 date columns, depending on what month it is and if it is a leap year.

Because the column header's are kind of complex, I'm choosing to pre-populate the GridView's columns with 16 date columns in xaml, then depending on what month it is etc., I delete n columns.  

The problem is that when I delete a column, it messes up my footer for the last column which is a total column.

It's probably easiest to understand if you see it in action.  To that end, I've created a very simplified version, with the code pasted below.  Just load it up, then press the Delete Column button.  You'll see what I mean.

xaml:
<Window x:Class="NMTimesheetUI.GridTest"
        Title="GridTest" Height="300" Width="600">
    <StackPanel Margin="10">
        <Button HorizontalAlignment="Right" Content="Delete Column" x:Name="btnDeleteColumn" Margin="0,0,0,10" Click="btnDeleteColumn_Click" />
        <telerik:RadGridView x:Name="gvTest" CanUserSortColumns="False" ShowColumnFooters="True" RowIndicatorVisibility="Visible" IsFilteringAllowed="False"
                             CanUserFreezeColumns="False" ShowInsertRow="False" AllowDrop="False" AutoGenerateColumns="False" CanUserDeleteRows="True" CanUserInsertRows="False"
                             CanUserResizeColumns="True" CanUserReorderColumns="False" GridLinesVisibility="Both" ShowGroupPanel="False" ShowColumnHeaders="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding jobName}" Width="110*" HeaderTextAlignment="Center" />
 
                <telerik:GridViewDataColumn Header="Mon" DataMemberBinding="{Binding hours1, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Tue" DataMemberBinding="{Binding hours2, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Wed" DataMemberBinding="{Binding hours3, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Thu" DataMemberBinding="{Binding hours4, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Fri" DataMemberBinding="{Binding hours5, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Sat" DataMemberBinding="{Binding hours6, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Sun" DataMemberBinding="{Binding hours7, Mode=TwoWay, UpdateSourceTrigger=LostFocus}" Width="40" HeaderTextAlignment="Center">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
 
                <telerik:GridViewDataColumn Header="Total" DataMemberBinding="{Binding totalHours, Mode=OneWay}">
                 
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="" SourceField="totalHours" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
 
 
                </telerik:GridViewDataColumn>
                 
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>
    </StackPanel>
</Window>

code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
 
namespace NMTimesheetUI
{
    /// <summary>
    /// Interaction logic for GridTest.xaml
    /// </summary>
    public partial class GridTest : Window
    {
        public GridTest()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(GridTest_Loaded);
        }
 
        void GridTest_Loaded(object sender, RoutedEventArgs e)
        {
            List<GridEntry> entries = GridEntry.getEntries();
            gvTest.ItemsSource = entries;
        }
 
        private void btnDeleteColumn_Click(object sender, RoutedEventArgs e)
        {
            int lastColumnIndex = gvTest.Columns.Count - 2;
            gvTest.Columns.RemoveAt(lastColumnIndex);
        }
    }
 
    public class GridEntry
    {
        #region Members
 
        public string jobName { get; set; }
        public decimal hours1 { get; set; }
        public decimal hours2 { get; set; }
        public decimal hours3 { get; set; }
        public decimal hours4 { get; set; }
        public decimal hours5 { get; set; }
        public decimal hours6 { get; set; }
        public decimal hours7 { get; set; }
 
        public decimal totalHours
        {
            get
            {
                return hours1 + hours2 + hours3 + hours4 + hours5 + hours6 + hours7;
            }
        }
 
        #endregion
 
        #region static Members
 
        public static List<GridEntry> getEntries()
        {
            List<GridEntry> entries = new List<GridEntry>();
            GridEntry john = new GridEntry {
                jobName = "John Lennon",
                hours1 = 1, hours2 = 2, hours3 = 3, hours4 = 4, hours5 = 5, hours6 = 0, hours7 = 0
            };
            entries.Add(john);
 
            GridEntry george = new GridEntry
            {
                jobName = "George Harrison",
                hours1 = 1,
                hours2 = 2,
                hours3 = 3,
                hours4 = 4,
                hours5 = 5,
                hours6 = 0,
                hours7 = 0
            };
            entries.Add(george);
 
 
            GridEntry paul = new GridEntry
            {
                jobName = "Paul McCartney",
                hours1 = 1,
                hours2 = 2,
                hours3 = 3,
                hours4 = 4,
                hours5 = 5,
                hours6 = 0,
                hours7 = 0
            };
            entries.Add(paul);
 
            GridEntry ringo = new GridEntry
            {
                jobName = "Ringo Starr",
                hours1 = 1,
                hours2 = 2,
                hours3 = 3,
                hours4 = 4,
                hours5 = 5,
                hours6 = 0,
                hours7 = 0
            };
            entries.Add(ringo);
 
 
            return entries;
        }
 
        #endregion
 
 
    }
}

Thanks!

Aaron

5 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 31 Aug 2012, 09:07 AM
Hi Aaron,


Unfortunately I was not be able to reproduce any problem. The only thing that I noticed is that "Total" column footer's value is not updating when I deleted a column.  Can you confirm this is the problem you described? If it not please provide me a screenshot that shows the issue. Please tell me what  version are yours binaries.

 

Regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Aaron
Top achievements
Rank 2
answered on 31 Aug 2012, 01:30 PM
I've attached a screenshot. 

I'm using 2011.1.419.40, which I believe is the latest version my license entitles me to.

Thanks.

Aaron
0
Yoan
Telerik team
answered on 31 Aug 2012, 02:02 PM
Hi Aaron,

In order to resolve your issue I would suggest you to download our latest libs. For your convenience, I've attached a working sample project.

 

All the best,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Aaron
Top achievements
Rank 2
answered on 02 Sep 2012, 07:44 PM

So, just to make sure I'm clear:

  1. Upgrading to the latest libraries should fix the problem
  2. I'll need to renew my subscription to get the latest libraries

Is that correct?

Aaron

0
Yoan
Telerik team
answered on 03 Sep 2012, 03:03 PM
Hi Aaron,

 Yes, you are correct. You can renew your subscription by logging in your control panel.

Regards,
Yoan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Aaron
Top achievements
Rank 2
Answers by
Yoan
Telerik team
Aaron
Top achievements
Rank 2
Share this question
or