Using the example class for serializing gridview (RadGridViewSettings) I am running into a problem, everything is great but when we attemt to LoadLayout for a gridview with groupdescriptors we get pixelWidth err every time. What could be the problem?
I know your going to say use the persist fw classes but we have special needs including that our grid filters are in a raddatafilter and there can be many settings files per gridview per each datafilter configuration and it is only partial saved in this way and some in our database too so our existing class works perfect and took a long time to develop... except if there is a groupdescriptor... we get this error.
Error:
Message: The parameter value must be greater than zero.
Parameter name: pixelWidth
Source: PresentationCore
Trace: at System.Windows.Media.Imaging.RenderTargetBitmap..ctor(Int32 pixelWidth, Int32 pixelHeight, Double dpiX, Double dpiY, PixelFormat pixelFormat)
at Telerik.Windows.Controls.FrameworkElementToImageConverter.ToImage(FrameworkElement element)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\Common\FrameworkElementToImageConverter.cs:line 26
at Telerik.Windows.Controls.GridView.GridViewGroupPanel.ConvertFrameworkElementToImage(FrameworkElement frameworkElement)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Grouping\GridViewGroupPanel.cs:line 185
at Telerik.Windows.Controls.GridView.GridViewGroupPanel.GetEffectiveContentForDescriptor(IGroupDescriptor descriptor)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Grouping\GridViewGroupPanel.cs:line 177
at Telerik.Windows.Controls.GridView.GridViewGroupPanel.PrepareContainerForItemOverride(DependencyObject element, Object item)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Grouping\GridViewGroupPanel.cs:line 144
at System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(DependencyObject container, Object item)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
at System.Windows.Controls.Panel.AddChildren(GeneratorPosition pos, Int32 itemCount)
at System.Windows.Controls.Panel.OnItemsChangedInternal(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.Panel.OnItemsChanged(Object sender, ItemsChangedEventArgs args)
at System.Windows.Controls.ItemContainerGenerator.OnItemAdded(Object item, Int32 index)
at System.Windows.Controls.ItemContainerGenerator.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.ItemContainerGenerator.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Controls.ItemCollection.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.ListCollectionView.ProcessCollectionChangedWithAdjustedIndex(NotifyCollectionChangedEventArgs args, Int32 adjustedOldIndex, Int32 adjustedNewIndex)
at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\RadObservableCollection.cs:line 235
at Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\ObservableItemCollection.cs:line 91
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
in
c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\RadObservableCollection.cs:line 281
at System.Collections.ObjectModel.Collection`1.Add(T item)
at NciDataTools.RadGridViewSettings.LoadState()
in
C:\..........\classes\ClassRadGridSettings.cs:line 275
at NciDataTools.WindowMain.gridScheduleUserSettingsLoad()
in
C:\..........\WindowMain.xaml.cs:line 1369
at NciDataTools.WindowMain.gridScheduleRefreshDataChanges()
in
C:\..........\WindowMain.xaml.cs:line 1345
at NciDataTools.WindowMain.gridScheduleDataWorker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
in
C:\..........\WindowMain.xaml.cs:line 1640
at System.ComponentModel.BackgroundWorker.OnRunWorkerCompleted(RunWorkerCompletedEventArgs e)
at System.ComponentModel.BackgroundWorker.AsyncOperationCompleted(Object arg)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Happens at this point (GroupDescriptors.Add(d)) when loading from the xml file.
if
(Settings.GroupSettings.Count > 0)
{
grid.GroupDescriptors.Clear();
foreach
(GroupSetting setting
in
Settings.GroupSettings)
{
ColumnGroupDescriptor d =
new
ColumnGroupDescriptor();
d.Column = (from c
in
grid.Columns.OfType<GridViewBoundColumnBase>()
where c.GetDataMemberName() == setting.PropertyName
select c).FirstOrDefault();
d.SortDirection = setting.SortDirection;
grid.GroupDescriptors.Add(d);
}
}
var style = steRTB.CurrentEditingStyle;
SelectedFontSize = (
double
)_conv.ConvertBack(
style.GetPropertyValue(TSpan.FontSizeProperty),
typeof
(
double
),
null
,
null
);
<
Window
x:Class
=
"ColumnGroupsExample.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
>
<
Window.Resources
>
<
DataTemplate
x:Key
=
"dtMainResource"
>
<
TextBlock
Text
=
"{Binding Path=MainResourceType}"
/>
</
DataTemplate
>
<
DataTemplate
x:Key
=
"dtAdjustedCost"
>
<
TextBlock
Text
=
"{Binding Path=AdjustedCost, StringFormat=C}"
HorizontalAlignment
=
"Right"
Padding
=
"0,0,4,0"
/>
</
DataTemplate
>
</
Window.Resources
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
</
Grid.RowDefinitions
>
<
telerik:RadGridView
Grid.Row
=
"0"
CanUserDeleteRows
=
"False"
CanUserInsertRows
=
"False"
CanUserSortColumns
=
"False"
ShowGroupPanel
=
"False"
AutoGeneratingColumn
=
"RadGridView_AutoGeneratingColumn"
ItemsSource
=
"{Binding Rows}"
RowIndicatorVisibility
=
"Collapsed"
AlternateRowBackground
=
"White"
AlternationCount
=
"2"
Background
=
"AliceBlue"
EditTriggers
=
"None"
HorizontalGridLinesBrush
=
"SlateGray"
SelectionMode
=
"Single"
SelectionUnit
=
"FullRow"
ShowColumnHeaders
=
"True"
IsFilteringAllowed
=
"False"
VerticalGridLinesBrush
=
"Transparent"
FrozenColumnCount
=
"1"
>
<
telerik:RadGridView.ColumnGroups
>
<
telerik:GridViewColumnGroup
Name
=
"Type"
Header
=
"Type"
/>
<
telerik:GridViewColumnGroup
Name
=
"Monthly"
Header
=
"Monthly"
/>
</
telerik:RadGridView.ColumnGroups
>
</
telerik:RadGridView
>
</
Grid
>
</
Window
>
namespace
ColumnGroupsExample
{
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.Navigation;
using
System.Windows.Shapes;
using
Telerik.Windows.Data;
using
Telerik.Windows.Controls;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public
partial
class
MainWindow : Window
{
private
ViewModel _viewModel;
public
MainWindow()
{
InitializeComponent();
_viewModel =
new
ViewModel();
this
.DataContext = _viewModel;
}
private
void
RadGridView_AutoGeneratingColumn(
object
sender, Telerik.Windows.Controls.GridViewAutoGeneratingColumnEventArgs e)
{
if
(e.Column.UniqueName.Contains(
"Week"
))
{
if
(e.Column.UniqueName.EndsWith(
"CostPlan"
))
{
DataTemplate costPlanDT =
new
DataTemplate();
FrameworkElementFactory spCostPlan =
new
FrameworkElementFactory(
typeof
(DockPanel));
spCostPlan.SetValue(DockPanel.LastChildFillProperty,
false
);
FrameworkElementFactory costPlanEntry =
new
FrameworkElementFactory(
typeof
(TextBox));
costPlanEntry.SetBinding(TextBox.TextProperty,
new
Binding(e.Column.UniqueName)
{
NotifyOnSourceUpdated =
true
,
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus,
StringFormat =
"F2"
});
costPlanEntry.SetValue(TextBox.FontSizeProperty, 10.0);
costPlanEntry.SetValue(TextBox.HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
costPlanEntry.SetValue(TextBox.WidthProperty, 80D);
spCostPlan.AppendChild(costPlanEntry);
costPlanDT.VisualTree = spCostPlan;
costPlanDT.Seal();
e.Column.Header =
"Cost Plan"
;
e.Column.CellTemplate = costPlanDT;
e.Column.Width = 88;
int
weekNumber = System.Convert.ToInt32(e.Column.UniqueName.Replace(
"Week"
,
""
).Replace(
"CostPlan"
,
""
));
((RadGridView)sender).ColumnGroups.Add(
new
GridViewColumnGroup()
{
Name = e.Column.UniqueName.Replace(
"CostPlan"
,
""
),
Header =
string
.Format(
"Week : {0} - {1}"
,
weekNumber,
DateTime.Now.AddDays((weekNumber - 1) * 7).ToString(
"dd/MM/yyyy"
))
});
e.Column.ColumnGroupName = e.Column.UniqueName.Replace(
"CostPlan"
,
""
);
}
else
if
(e.Column.UniqueName.EndsWith(
"AssessedCost"
))
{
DataTemplate assessedCostDT =
new
DataTemplate();
FrameworkElementFactory spFactory =
new
FrameworkElementFactory(
typeof
(DockPanel));
spFactory.SetValue(DockPanel.LastChildFillProperty,
false
);
FrameworkElementFactory assessedCostsEntry =
new
FrameworkElementFactory(
typeof
(TextBox));
assessedCostsEntry.SetBinding(TextBox.TextProperty,
new
Binding(e.Column.UniqueName)
{
NotifyOnSourceUpdated =
true
,
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus,
StringFormat =
"F2"
});
assessedCostsEntry.SetValue(TextBox.FontSizeProperty, 10.0);
assessedCostsEntry.SetValue(TextBox.HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
assessedCostsEntry.SetValue(TextBox.WidthProperty, 80D);
spFactory.AppendChild(assessedCostsEntry);
assessedCostDT.VisualTree = spFactory;
assessedCostDT.Seal();
e.Column.Header =
"Assessed Cost"
;
e.Column.CellTemplate = assessedCostDT;
e.Column.Width = 88;
e.Column.ColumnGroupName = e.Column.UniqueName.Replace(
"AssessedCost"
,
""
);
}
else
if
(e.Column.UniqueName.EndsWith(
"Difference"
))
{
DataTemplate differenceDt =
new
DataTemplate();
FrameworkElementFactory difference =
new
FrameworkElementFactory(
typeof
(TextBlock));
difference.SetBinding(TextBlock.TextProperty,
new
Binding(e.Column.UniqueName)
{
StringFormat =
"C"
});
difference.SetValue(TextBlock.FontSizeProperty, 10.0);
difference.SetValue(TextBlock.PaddingProperty,
new
Thickness(0, 0, 4, 0));
difference.SetValue(TextBlock.TextAlignmentProperty, TextAlignment.Right);
difference.SetValue(TextBlock.WidthProperty, 80D);
differenceDt.VisualTree = difference;
differenceDt.Seal();
e.Column.Header =
"Difference"
;
e.Column.CellTemplate = differenceDt;
e.Column.ColumnGroupName = e.Column.UniqueName.Replace(
"Difference"
,
""
);
}
else
if
(e.Column.UniqueName.EndsWith(
"CF03DetailDateUid"
))
{
//Don't show this column
e.Column.IsVisible =
false
;
}
}
else
{
if
(e.Column.UniqueName ==
"MainResourceType"
)
{
e.Column.CellTemplate = (DataTemplate)
this
.Resources[
"dtMainResource"
];
e.Column.Header =
"Resource Type"
;
e.Column.ColumnGroupName =
"Type"
;
}
else
if
(e.Column.UniqueName ==
"Projection"
)
{
DataTemplate projectionDT =
new
DataTemplate();
FrameworkElementFactory spFactory =
new
FrameworkElementFactory(
typeof
(DockPanel));
spFactory.SetValue(DockPanel.LastChildFillProperty,
false
);
FrameworkElementFactory projectionEntry =
new
FrameworkElementFactory(
typeof
(TextBox));
projectionEntry.SetBinding(TextBox.TextProperty,
new
Binding(e.Column.UniqueName)
{
NotifyOnSourceUpdated =
true
,
UpdateSourceTrigger = UpdateSourceTrigger.LostFocus,
StringFormat =
"F2"
});
projectionEntry.SetValue(TextBox.FontSizeProperty, 10.0); ;
projectionEntry.SetValue(TextBox.StyleProperty, (Style)
this
.Resources[
"detailEntry"
]);
projectionEntry.SetValue(TextBox.HorizontalContentAlignmentProperty, HorizontalAlignment.Right);
projectionEntry.SetValue(TextBox.WidthProperty, 80D);
spFactory.AppendChild(projectionEntry);
projectionDT.VisualTree = spFactory;
projectionDT.Seal();
e.Column.CellTemplate = projectionDT;
e.Column.Header =
"Projection"
;
e.Column.ColumnGroupName =
"Monthly"
;
}
else
if
(e.Column.UniqueName ==
"AdjustedCost"
)
{
//#FFCCFFFF
e.Column.CellTemplate = (DataTemplate)
this
.Resources[
"dtAdjustedCost"
];
e.Column.Header =
"Adjusted Costs"
;
e.Column.ColumnGroupName =
"Monthly"
;
}
}
}
}
}
View Model
namespace
ColumnGroupsExample
{
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.ComponentModel;
using
System.Dynamic;
using
System.Collections.ObjectModel;
using
System.Windows.Input;
public
class
ViewModel : INotifyPropertyChanged
{
public
event
PropertyChangedEventHandler PropertyChanged;
private
ObservableCollection<dynamic> _rows;
/// <summary>
///
/// </summary>
/// <param name="name"></param>
protected
void
OnPropertyChanged(
string
name)
{
if
(PropertyChanged !=
null
)
{
PropertyChanged(
this
,
new
PropertyChangedEventArgs(name));
}
}
public
ViewModel()
{
_rows =
new
ObservableCollection<dynamic>();
CreateRow(
"Staff"
);
CreateRow(
"Labour"
);
CreateRow(
"Plant"
);
CreateRow(
"Temp Materials"
);
CreateRow(
"Perm Materials"
);
CreateRow(
"Sub Contract"
);
}
public
void
CreateRow(
string
type)
{
var row =
new
ExpandoObject()
as
IDictionary<
string
, Object>;
decimal
zero = 0;
Guid? blankUid = Guid.Empty;
row.Add(
"MainResourceType"
, type);
row.Add(
"AdjustedCost"
, zero);
row.Add(
"Projection"
, zero);
for
(
int
i = 1; i <= 13; i++)
{
row.Add(
string
.Format(
"Week{0}CostPlan"
, i), zero);
row.Add(
string
.Format(
"Week{0}AssessedCost"
, i), zero);
row.Add(
string
.Format(
"Week{0}Difference"
, i), zero);
row.Add(
string
.Format(
"Week{0}CF03DetailDateUid"
, i), blankUid);
}
_rows.Add(row);
}
public
ObservableCollection<dynamic> Rows
{
get
{
return
_rows;
}
set
{
if
(_rows != value)
{
_rows = value;
OnPropertyChanged(
"Rows"
);
}
}
}
}
}
Please advise on how to get the column groups displaying correctly.
Cheers
Steve