I search the web and download the sample code from Vladimir Enchev's blog but fail to compile it becuase that the sample is for Silverlight 2 only.
http://blogs.telerik.com/vladimirenchev/posts/09-04-08/how_to_save_and_load_settings_with_radgridview_for_silverlight.aspx
I try to follow the QuickStart.Example but fail to implement the OnUnload event in my Silverlight control.
Then, I added the RadGridViewSettings class to my project and followed Vladimir Enchev's syntax by setting RadGridViewSettings.IsEnabled to true.
<UserControl x:Class="SaveLoadSettingsWithRadGridViewForSilverlight.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
xmlns:ts="clr-namespace:Telerik.Settings">
<Gridx:Name="LayoutRoot"Background="White">
<telerik:RadGridView ts:RadGridViewSettings.IsEnabled="True" x:Name="RadGridView1" />
</Grid>
</UserControl>
Sadly, I got another error,
The property 'IsEnabled' does not exist on the type 'RadGridView' in the XML namespace 'clr-namespace:Telerik.Windows.Controls.GridView.Settings'.
Is there any sample code which will be compiled and works with RadControls for Silverlight Q2 2009 and Silvelight 3? Also, the sample code does not depend on Telerik.Windows.QuickStart.dll.
Thanks,
Simon
49 Answers, 1 is accepted
The OnUnload event is a feature of our QSF Application and that event is not available in normal Silverlight applications. Nevertheless you can substitute the OnUnload event with the Application.Exit event.
I am sending you an application that demonstrates this approach.
Greetings,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The property 'IsEnabled' does not exist on the type 'RadGridView' in the XML namespace 'clr-namespace:Telerik.Settings'.
My code is,
<
UserControl x:Class="VirtualHealthClub.MyClients.MyClientsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
xmlns:controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
xmlns:grid="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView"
xmlns:formatter="clr-namespace:VirtualHealthClub.MyClients.Formatter"
xmlns:ts="clr-namespace:Telerik.Settings"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid x:Name="LayoutRoot" Background="White">
<controls:RadGridView x:Name="radGridView"
IsReadOnly="True" AutoGenerateColumns="False"
ItemsSource="{Binding MyClients}"
RowLoaded="radGridView_RowLoaded"
ts:RadGridViewSettings.IsEnabled="True">
......
......
</controls:RadGridView>
</Grid>
</
UserControl>
Simon
If you add one method called GetIsEnabled to the GridViewSettings class the error should disappear.
public static bool GetIsEnabled(DependencyObject dependencyObject) |
{ |
return (bool)dependencyObject.GetValue(IsEnabledProperty); |
} |
If you are using GridViewSettings.IsEnabled attached property you should not load or save the settings manually as this will be done by the GridViewSettings class itself. In case you need more flexibility and control over the save/load process simply eliminate the use of GridViewSettings.IsEnabled and manually call LoadState() and SaveState().
Hope this helps.
All the best,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Value does not fall within the expected range.
I troubleshoot and figure out that the error is caused in the SaveState(),
GridViewHeaderCell
cell = headerRow.ChildrenOfType<GridViewHeaderCell>().Where(c => c.Column.UniqueName == setting.PropertyName).FirstOrDefault();
I'm using DataMemberBinding to bind data instead of UniqueName. Consequently, cell is always null.
Would you please help?
Simon
UniqueName should have a non null value event if you are using DisplayMemberBinding. Is it null in your case? Even if it is null i doubt that it is causing the error. Anyway, you can try the following but it will only work for GridViewDataColumns:
cell = headerRow.ChildrenOfType<GridViewHeaderCell>().Where(c => ((GridViewDataColumn)c.Column).DataMemberBinding.Path.Path == setting.PropertyName).FirstOrDefault(); |
Have you applied any custom templates to the gird that might be causing this error?
Sincerely yours,
Milan
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The first column of my grid is,
<controls:GridViewDataColumn Width="80" Header="Group" TextWrapping="Wrap" DataMemberBinding="{Binding GroupName}" IsGroupable="True" />
I troubleshoot and confirm that the UniqueName is null.
After I have updated the GridViewSettings class with your code, I can save the settings. However, the LoadState() is still broken. It fails at the grid.Columns.Add(column) statement while restoring the first column settings.
foreach (ColumnSetting setting in Settings.ColumnSettings)
{
GridViewDataColumn column = new GridViewDataColumn();
column.UniqueName = setting.UniqueName;
column.HeaderText = setting.HeaderText;
if (setting.Width != null)
{
column.Width = new GridLength(setting.Width.Value);
}
grid.Columns.Add(column);
}
The error message is,
{System.ArgumentException: Value does not fall within the expected range.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper obj, DependencyProperty property, DependencyObject doh)
at MS.Internal.XcpImports.SetValue(INativeCoreTypeWrapper doh, DependencyProperty property, Object obj)
at System.Windows.DependencyObject.SetObjectValueToCore(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Controls.ContentControl.set_Content(Object value)
at Telerik.Windows.Controls.GridView.GridViewHeaderCell.SetHeaderText()
at Telerik.Windows.Controls.GridView.GridViewHeaderCell.OnApplyTemplate()
at System.Windows.FrameworkElement.OnApplyTemplate(IntPtr nativeTarget)}
Please help.
Simon
Please check this demo for the latest version of the settings class:
http://demos.telerik.com/silverlight/#GridView/SaveLoadSettings
All the best,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I added the latest demo version of the settings class to my projects. I could compile but got a runtime error at the statement (in the Save() method), serializer.WriteObject(stream, this). The error was,
{System.Runtime.Serialization.InvalidDataContractException: Type 'System.Windows.UIElement' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.
Simon
I've attached small running example to illustrate you how to achieve your goal. Basically all you need is to set the grid this attached behavior and everything will start to work. You can perform changes in runtime and next time when you start the application you will get all previous changes applied.
Regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I really like the idea that you can save & load a grid's setting using an attached behavior "IsEnabled=True" but this code does not work in the Q3 release.
I tried converting this over to Q3 but I could not get it working. I then tried taking the source of RadGridViewSetting.cs from the demo app in the Q3 release but, even though I can see IsEnabled in the path when I try to add the property to a grid, the compiler complains that IsEnabled is not a property of RadGridView Settings.
Could you provide a copy that works with the latest release (or even better, can you make sure it's working with the latest internal build which is what I'm using.
Thanks in advance,
Steve
namespace Telerik.Windows.Controls.GridView.Settings |
{ |
public class RadGridViewSettings |
{ |
public RadGridViewSettings() |
{ |
// |
} |
public class RadGridViewApplicationSettings : Dictionary<string, object> |
{ |
private RadGridViewSettings settings; |
private DataContractSerializer serializer = null; |
public RadGridViewApplicationSettings() |
{ |
// |
} |
//****** etc |
//... |
public static readonly DependencyProperty IsEnabledProperty |
= DependencyProperty.RegisterAttached("IsEnabled", typeof(bool), typeof(RadGridViewSettings), |
new PropertyMetadata(new PropertyChangedCallback(OnIsEnabledPropertyChanged))); |
public static void SetIsEnabled(DependencyObject dependencyObject, bool enabled) |
{ |
dependencyObject.SetValue(IsEnabledProperty, enabled); |
} |
private static void OnIsEnabledPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) |
{ |
RadGridView grid = dependencyObject as RadGridView; |
if (grid != null) |
{ |
if ((bool)e.NewValue) |
{ |
RadGridViewSettings settings = new RadGridViewSettings(grid); |
settings.Attach(); |
} |
} |
} |
Then in my xaml file I have...
xmlns:gridViewSettings="clr-namespace:Telerik.Windows.Controls.GridView.Settings" |
... |
... |
<telerikGridView:RadGridView x:Name="rgvProperties" AutoGenerateColumns="False" CanUserInsertRows="True" |
SelectionChanged="rgvProperties_SelectionChanged" RowLoaded="rgvProperties_RowLoaded" |
RowEditEnded="rgvProperties_RowEditEnded" DataLoadMode="Asynchronous" ScrollMode="Deferred" |
Height="300" ValidationMode="Cell" AddingNewDataItem="rgvProperties_AddingNewDataItem" |
gridViewSettings:RadGridViewSettings.IsEnabled="True"> |
Intellisense gives me RadGridViewSettings when I get to the : of gridViewSettings. Then it shows me IsEnabled as a setting. However when I select it, I see a red underline under IsEnabled and hovering there says it's not found. If I compile it, I get an error saying
Error 5 The property 'IsEnabled' does not exist on the type 'RadGridView' in the XML namespace 'clr-namespace:Telerik.Windows.Controls.GridView.Settings'. C:\Users\Steve\Documents\Visual Studio 2008\Projects\RealMax\RealMax\Views\About.xaml 47 34 RealMax
You can check our example for the latest version:
http://demos.telerik.com/silverlight/#GridView/SaveLoadSettings
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Steve
Please define getter for this property and let me know how it goes. Here is an example:
public static bool GetIsEnabled(DependencyObject dependencyObject)
{
return (bool) dependencyObject.GetValue(IsEnabledProperty);
}
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The first time I ran it, the grid looked very strange. I think that's because I had saved its state using a previous version of the code and maybe it was messed up when it tried to restore the old data. So I reset the grid saved state in code behind (I just set it up on a button to test it) and then tried it again.
This time, the grid looked fine when it first loaded, but when I changed column ordering or column sizing and then came back to the grid, it was still in its original state. Now my assumtion is that if I made any changes it would automatically save the grid layout....
Any thoughts?
It seems that DataMemberBinding is Null.
Steve
Can you post more info how these columns are bound in your case?
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Anyhow. Here's how I get data into the grid.
private void LoadData() |
{ |
activity.IsActive = true; |
domainContext.Load(domainContext.GetPropertiesAndLiensQuery(), LoadProperties, false); |
} |
private void LoadProperties(LoadOperation lo) |
{ |
activity.IsActive = false; |
if (lo.HasError) |
{ |
// an error occured so I need to handle it... |
lo.MarkErrorAsHandled(); |
return; |
} |
var view = new QueryableCollectionView(domainContext.rtp_Properties); |
rgvProperties.ItemsSource = view; |
rgvProperties.CanUserInsertRows = true; |
dfPropertyDetails.ItemsSource = view; |
} |
The rgvProperties is the GridView and the dfPropertyDetails is the dataForm.
Steve
My question actually was how and when columns are created in your case since according the your grid declaration you've set AutoGenerateColumns to false. Save/load setting crash is related to null DataMemberBinding and that is why I'm asking for more info if this set at all for your custom columns and at what stage.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Here are the column declarations.
<telerikGridView:RadGridView.Columns> |
<telerikGridView:GridViewDataColumn Header="Address" DataMemberBinding="{Binding Address}" /> |
<telerikGridView:GridViewDataColumn Header="Full Address" DataMemberBinding="{Binding FullAddress}" IsReadOnly="True" /> |
<telerikGridView:GridViewDataColumn Header="City" DataMemberBinding="{Binding City}" /> |
<telerikGridView:GridViewDataColumn Header="State" DataMemberBinding="{Binding State}" /> |
<telerikGridView:GridViewDataColumn Header="Zip" DataMemberBinding="{Binding Zip}" /> |
<telerikGridView:GridViewDataColumn Header="Beds" DataMemberBinding="{Binding Bedrooms}" /> |
<telerikGridView:GridViewDataColumn Header="Baths" DataMemberBinding="{Binding Baths}" /> |
</telerikGridView:RadGridView.Columns> |
<telerikGridView:RadGridView x:Name="rgvProperties" AutoGenerateColumns="False" CanUserInsertRows="True" |
RowLoaded="rgvProperties_RowLoaded" AddingNewDataItem="rgvProperties_AddingNewDataItem" |
RowEditEnded="rgvProperties_RowEditEnded" DataLoadMode="Asynchronous" ScrollMode="Deferred" |
Height="300" ValidationMode="Cell" > |
<!--gridViewSettings:RadGridViewSettings.IsEnabled="True">--> |
<telerikGridView:RadGridView.ScrollPositionIndicatorTemplate> |
<DataTemplate> |
<Border HorizontalAlignment="Right" Width="Auto" Height="Auto" BorderBrush="#7FC2CCE1" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8" VerticalAlignment="Center"> |
<Border Width="Auto" BorderBrush="#FFF6F1EC" BorderThickness="1,1,1,1" Height="Auto" CornerRadius="7,7,7,7"> |
<Border.Background> |
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> |
<GradientStop Color="#7FC2CCE1" Offset="1"/> |
<GradientStop Color="#BFC2CCE1" Offset="0"/> |
</LinearGradientBrush> |
</Border.Background> |
<Border Width="Auto" BorderBrush="#FF899BC1" BorderThickness="1,1,1,1" Height="Auto" CornerRadius="5,5,5,5" Background="#FFEBEFF7" Margin="5,5,5,5"> |
<ContentPresenter Margin="40,5,40,6" Content="{Binding}"> |
<ContentPresenter.ContentTemplate> |
<DataTemplate> |
<Grid IsHitTestVisible="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"> |
<Grid.RowDefinitions> |
<RowDefinition Height="30" /> |
<RowDefinition Height="Auto" /> |
</Grid.RowDefinitions> |
<StackPanel Grid.Row="0" VerticalAlignment="Center" > |
<TextBlock Text="{Binding Address}" Foreground="#ff8FB3FF" FontSize="12" /> |
</StackPanel> |
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center"> |
<TextBlock Text="{Binding City}" Foreground="#ff8FB3FF" FontSize="12" /> |
<TextBlock Text="{Binding State}" FontSize="12" Foreground="#ff8FB3FF" Margin="4,0,0,0"/> |
<TextBlock Text="{Binding Zip}" FontSize="12" Foreground="#ff8FB3FF" Margin="4,0,0,0"/> |
</StackPanel> |
</Grid> |
</DataTemplate> |
</ContentPresenter.ContentTemplate> |
</ContentPresenter> |
</Border> |
</Border> |
</Border> |
</DataTemplate> |
</telerikGridView:RadGridView.ScrollPositionIndicatorTemplate> |
<telerikNavigation:RadContextMenu.ContextMenu> |
<telerikNavigation:RadContextMenu Opened="rcmProperties_Opened" ItemClick="rcmProperties_ItemClick"> |
<telerikNavigation:RadContextMenu.Items> |
<telerikNavigation:RadMenuItem Header="Add New Property" /> |
<telerikNavigation:RadMenuItem Header="Edit Item" /> |
<telerikNavigation:RadMenuItem Header="View and Edit property" /> |
<telerikNavigation:RadMenuItem Header="Delete Property" /> |
</telerikNavigation:RadContextMenu.Items> |
</telerikNavigation:RadContextMenu> |
</telerikNavigation:RadContextMenu.ContextMenu> |
<telerikGridView:RadGridView.Columns> |
<telerikGridView:GridViewDataColumn Header="Address" DataMemberBinding="{Binding Address}" /> |
<telerikGridView:GridViewDataColumn Header="Full Address" DataMemberBinding="{Binding FullAddress}" IsReadOnly="True" /> |
<telerikGridView:GridViewDataColumn Header="City" DataMemberBinding="{Binding City}" /> |
<telerikGridView:GridViewDataColumn Header="State" DataMemberBinding="{Binding State}" /> |
<telerikGridView:GridViewDataColumn Header="Zip" DataMemberBinding="{Binding Zip}" /> |
<telerikGridView:GridViewDataColumn Header="Beds" DataMemberBinding="{Binding Bedrooms}" /> |
<telerikGridView:GridViewDataColumn Header="Baths" DataMemberBinding="{Binding Baths}" /> |
</telerikGridView:RadGridView.Columns> |
</telerikGridView:RadGridView> |
Then the grid is populated as soon as the page load code is executed and I get control. Of course it's async but I'm only pulling in about 20 rows so it doesn't take long.
public Home() |
{ |
InitializeComponent(); |
this.Title = ApplicationStrings.ApplicationName + ApplicationStrings.HomePageTitle; |
//var x = new RadGridViewSettings(rgvProperties); |
//x.ResetState(); |
if (domainContext == null) domainContext = new RealMaxDomainContext(); |
LoadDataIfAuthenticated(); |
} |
/// <summary> |
/// Executes when the user navigates to this page. |
/// </summary> |
protected override void OnNavigatedTo(NavigationEventArgs e) |
{ |
} |
private void LoadDataIfAuthenticated() |
{ |
if (!WebContext.Current.User.IsAuthenticated) |
{ |
try |
{ |
WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null); |
} |
catch |
{ |
NavigateToLoginPage(); |
} |
} |
else LoadData(); |
} |
private void LoadData() |
{ |
activity.IsActive = true; |
domainContext.Load(domainContext.GetPropertiesAndLiensQuery(), LoadProperties, false); |
} |
private void LoadProperties(LoadOperation lo) |
{ |
activity.IsActive = false; |
if (lo.HasError) |
{ |
// an error occured so I need to handle it... |
lo.MarkErrorAsHandled(); |
return; |
} |
var view = new QueryableCollectionView(domainContext.rtp_Properties); |
rgvProperties.ItemsSource = view; |
rgvProperties.CanUserInsertRows = true; |
dfPropertyDetails.ItemsSource = view; |
} |
private void Application_UserLoaded(LoadUserOperation operation) |
{ |
if (operation.HasError || !WebContext.Current.User.IsAuthenticated) |
{ |
if (operation.HasError) operation.MarkErrorAsHandled(); |
NavigateToLoginPage(); |
} |
else LoadData(); |
} |
You can modify LoadState() method to fix this:
...
foreach (ColumnSetting setting in Settings.ColumnSettings)
{
GridViewDataColumn column = new GridViewDataColumn();
column.UniqueName = setting.UniqueName;
column.DataMemberBinding = new Binding(setting.PropertyName);
column.Header = setting.Header;
if (setting.Width != null)
{
column.Width = new GridViewLength(setting.Width.Value);
}
grid.Columns.Add(column);
}
...
I've attached an example project for reference.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I'm not defining the grid view any differently (though the project is much more complicated that the sample project as one would expect) .. the biggest difference is that I am using SL4 and the samples are running SL3.
Any ideas?
Most probably you have UIElement in some of the columns Header property - can you verify this?
Kind regards,
Vlad
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.
This is, however, going to be a big problem for us... The column with the check box in the header is for toggling checking all rows.
<telerikGrid:GridViewDataColumn.Header> |
<CheckBox Checked="CheckAllCheckBox_Checked" Unchecked="CheckAllCheckBox_Unchecked" |
VerticalAlignment="Center" HorizontalAlignment="Center" /> |
</telerikGrid:GridViewDataColumn.Header> |
Any ideas?
The only thing I can think of is modifying the settings class to be less destructive to the grid columns - i.e. instead of clearing out all the columns and rebuilding, is to restore the settings by searching for the column by name and applying saved settings like width and display index (the supplied class does not save the order of the columns).
Your idea seems very good one.
Other approach may be to create an attached property, which you can set on specific columns and "mark them" as not persisted into the settings. Then when you save the column's state you can check this property and depending on the value decide whether or not to persist this column's settings.
Another thing you can do is to verify if the Header property of the column is a UIElement. If it is you may not want to persist its value.
Regards,
Stefan Dobrev
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.
OK, I am going with the idea to change columns when the layout is loaded rather than when recreate them. It works fine since we don't allow users to add or remove columns (removal is by setting column IsVisible to false).
But I have two questions..
1. The "ApplicationExit" event is inappropriate for saving the grid settings in my application since we are using the navigation framework. Instead, I am catching events like columns reordered, sorting changed to call SaveState(). However, there is no event for catching IsVisible... Any ideas how I could catch that? If not, my request is to add an event handler to the grid named something like "GridLayoutChanged" which developers could use to know when the grid has visually changed (and is finished since in the case of reordering columns, multiple events are fired).
2. Further to above, I'd like to only save the settings when I leave the current view.. is there any event I can catch like "Grid Unloaded" which would tell me the grid is going out of view? Alternately, I know when I'm leaving .. is there any way to tell the attached GridViewSettings class to call "SaveState" right now?
Thanks
Greg
Since there is not Unloaded event by default in Silverlight you can check this blog post to know more how to create such.
All the best,
Vlad
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.
i am attempting to save the grid settings using the code samples at http://demos.telerik.com/silverlight/#GridView/Selection as a starting point, and receiving an error whenever i attempt to load settings that include a "group by" column setting. here's the xaml for my grid. The error i receive is "An unhandled exception ('Unhandled error in Silverlight Application Code:4004 Category: ManagedRuntimeError Message: System.ArgumentException: Invalid property or field 'Property1' for type:Entity". I've also get a similar error when i combine the "save settings" feature with the grid context menu that allows users to deselect tables.
i only have the latest telerik silverlight v4 DLLs installed, so i can't tell if the problem is with my code or not.
<telerikGridView:RadGridView x:Name="gridmyData" ItemsSource="{Binding Data, ElementName=MyDataSource}" CanUserFreezeColumns="False" IsReadOnly="True/>
I have tried to reproduce your problem but everything works fine on my side. Please, find attached a sample project and in case there is something I am missing to match your requirements, do not hesitate to get back to us.
Maya
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.
The sample project I have sent to you is also using Trial version of our binaries but from our latest internal build, so most probably the issues you encountered had already been fixed. However, the most important thing is that now everything is working fine on your side too.
Maya
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.
GridViewCheckBoxColumn and GridViewComboBoxColumn?
I believe that the approach used in our demo will work no matter of column types used in the grid.
Kind regards,Vlad
the Telerik team
I'm afraid that you cannot persist templates.
Greetings,Vlad
the Telerik team
Could I maybe add templates at runtime once I know what the columns are, just as a workaround.
I just would like to use the save/reload feature if possiblke.
You can plug the cell templates in this code:
foreach
(ColumnSetting setting
in
Settings.ColumnSettings)
{
ColumnSetting currentSetting = setting;
GridViewDataColumn column = (from c
in
grid.Columns.OfType<GridViewDataColumn>()
where c.UniqueName == currentSetting.UniqueName
select c).FirstOrDefault();
if
(column !=
null
)
{
if
(currentSetting.DisplayIndex !=
null
)
{
column.DisplayIndex = currentSetting.DisplayIndex.Value;
}
if
(setting.Width !=
null
)
{
column.Width =
new
GridViewLength(setting.Width.Value);
}
}
}
Vlad
the Telerik team
Thanks
Indeed the code I've posted is part of RadGridViewSettings class from our demo. You can use it to plug your own logic like loading of templates.
Sincerely yours,Vlad
the Telerik team
public
class
PropertySetting
{
string
_PropertyName;
public
string
PropertyName
{
get
{
return
_PropertyName;
}
set
{
_PropertyName = value;
}
}
}
The error is caught in the 'catch' section of this try/catch block:
if
(grid.Columns !=
null
)
{
try
{
Settings.ColumnSettings.Clear();
foreach
(GridViewColumn column
in
grid.Columns)
{
if
(column
is
GridViewDataColumn)
{
GridViewDataColumn dataColumn = (GridViewDataColumn)column;
ColumnSetting setting =
new
ColumnSetting();
setting.PropertyName = dataColumn.DataMemberBinding.Path.Path;
setting.UniqueName = dataColumn.UniqueName;
setting.Header = dataColumn.Header;
setting.Width = dataColumn.ActualWidth;
setting.DisplayIndex = dataColumn.DisplayIndex;
setting.IsVisible = dataColumn.IsVisible;
Settings.ColumnSettings.Add(setting);
}
}
}
catch
{
//
}
}
The error is as follows:
Type 'System.Windows.UIElement' cannot be serialized. Consider marking it with the DataContractAttribute
attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.
Alternatively, you can ensure that the type is public and has a parameterless constructor - all public
members of the type will then be serialized, and no attributes will be required.
Here is the gridview defintion xaml code:
<
telerikGridView:RadGridView
x:Name
=
"CommissiondataGrid"
Margin
=
"8,75,8,8"
ShowGroupPanel
=
"False"
ItemsSource
=
"{Binding CommissionList}"
AutoGenerateColumns
=
"False"
DataLoadMode
=
"Asynchronous"
Deleting
=
"CommissiondataGrid_Deleting"
RowEditEnded
=
"CommissiondataGrid_RowEditEnded"
AddingNewDataItem
=
"CommissiondataGrid_AddingNewDataItem"
ShowInsertRow
=
"True"
RowValidating
=
"CommissiondataGrid_RowValidating"
ActionOnLostFocus
=
"None"
CanUserInsertRows
=
"False"
SelectionChanged
=
"CommissiondataGrid_SelectionChanged"
MouseLeave
=
"CommissiondataGrid_MouseLeave"
>
<
telerik:RadGridView.GroupRowStyle
>
<
Style
TargetType
=
"telerik:GridViewGroupRow"
>
<
Setter
Property
=
"ShowHeaderAggregates"
Value
=
"False"
/>
</
Style
>
</
telerik:RadGridView.GroupRowStyle
>
<
telerikGridView:RadGridView.Columns
>
<
telerikGridView:GridViewDataColumn
DataMemberBinding
=
"{Binding CommissionSeq}"
Header
=
"Seq#"
/>
<
telerikGridView:GridViewDataColumn
DataMemberBinding
=
"{Binding PartCategory, Converter={StaticResource UpperConverter}, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
Header
=
"Part Category"
/>
<
telerikGridView:GridViewCheckBoxColumn
DataMemberBinding
=
"{Binding PartRepaired, Mode=TwoWay}"
>
<
telerikGridView:GridViewCheckBoxColumn.Header
>
<
TextBlock
Text
=
"Commission for Repaired Parts"
TextWrapping
=
"Wrap"
/>
</
telerikGridView:GridViewCheckBoxColumn.Header
>
</
telerikGridView:GridViewCheckBoxColumn
>
<
telerikGridView:GridViewDataColumn
DataMemberBinding
=
"{Binding RangeStart, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
Header
=
"Range Start"
TextAlignment
=
"Right"
DataFormatString
=
"{}{0:n2}"
/>
<
telerikGridView:GridViewDataColumn
DataMemberBinding
=
"{Binding RangeEnd, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
Header
=
"Range End"
TextAlignment
=
"Right"
DataFormatString
=
"{}{0:n2}"
/>
<
telerikGridView:GridViewDataColumn
DataMemberBinding
=
"{Binding CommissionPct, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}"
TextAlignment
=
"Right"
DataFormatString
=
"{}{0:P2}"
>
<
telerikGridView:GridViewDataColumn.Header
>
<
TextBlock
Text
=
"Commission Percentage"
TextWrapping
=
"Wrap"
/>
</
telerikGridView:GridViewDataColumn.Header
>
</
telerikGridView:GridViewDataColumn
>
<
telerikGridView:GridViewCheckBoxColumn
DataMemberBinding
=
"{Binding GrossNet, Mode=TwoWay}"
>
<
telerikGridView:GridViewCheckBoxColumn.Header
>
<
TextBlock
Text
=
"Gross Amt (Checked) Net Amount (Unchecked)"
TextWrapping
=
"Wrap"
/>
</
telerikGridView:GridViewCheckBoxColumn.Header
>
</
telerikGridView:GridViewCheckBoxColumn
>
</
telerikGridView:RadGridView.Columns
>
</
telerikGridView:RadGridView
>
So far I have not found a solution around this problem. Has anybody experienced the same issue?
Thanks,
Bryan
The issue most probably was caused by the Header property of the check box column (CheckBox in case of multiple selection) . You can remove save/load of the Header for this column type conditionally.
Best wishes,Vlad
the Telerik team
i am trying to use ure code for saving my radgridview collums order..
However i am using telerik silverlight grid of older version 2010.1.309.1030.
When i replace your dlls with my version dlls then the collumn ordering does not work.
Is there any alternate way in the previous version to achieve the same.
just change to old dlls check with your code the collumn reordering will not work.
Do let me know asap.
Operation not permitted on IsolatedStorageFileStream.
there was an error on the onunload part. can you please post a sample application that saves the gridview settings for silverlight 4? thanks :)
Regards,
Loraine
Generally, you may run through our demos for getting the latest version of the Save and Load RadGridView Settings example. Furthermore, you may execute your own version of the examples in order to test it locally.
Let me know if you encounter any other difficulties and you need an assistance.
Maya
the Telerik team
Actually, the recommended approach now is to work with our RadPersistenceFramework to save and load the settings of RadGridView. Please take a look at this demo for a reference.
Let us know if you need any further assistance with it.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>