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:
code:
Thanks!
Aaron
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"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
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