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

How To Save and load settings with RadGridView for Silverlight?

49 Answers 891 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Simon Chan
Top achievements
Rank 1
Simon Chan asked on 18 Sep 2009, 09:42 PM
I'm testing the RadControls for Silverlight Q2 2009 and Silvelight 3. I fail to save and load settings with RadGridView for Silverlight.

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

Sort by
0
Milan
Telerik team
answered on 22 Sep 2009, 12:08 PM
Hi Simon Chan,

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.
0
Simon Chan
Top achievements
Rank 1
answered on 23 Sep 2009, 07:49 PM
The sample project works perfectly. Hoiwever, when I add the file, RadGridViewSettings.cs, to my project and reference it in the XMAL file, I got the error
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

 


0
Milan
Telerik team
answered on 24 Sep 2009, 11:34 AM
Hello Simon Chan,

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.
0
Simon Chan
Top achievements
Rank 1
answered on 24 Sep 2009, 01:54 PM
Thanks. I added the code and I am able to compile my projects. However, I get a runtime error and the message is,
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
0
Milan
Telerik team
answered on 24 Sep 2009, 02:32 PM
Hello Simon Chan,

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.
0
Simon Chan
Top achievements
Rank 1
answered on 24 Sep 2009, 08:13 PM

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
  

 

0
Vlad
Telerik team
answered on 25 Sep 2009, 05:55 AM
Hello 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.
0
Simon Chan
Top achievements
Rank 1
answered on 25 Sep 2009, 01:51 PM

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
0
Vlad
Telerik team
answered on 02 Oct 2009, 07:00 AM
Hi 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.
0
Steve Y
Top achievements
Rank 2
answered on 01 Dec 2009, 07:22 PM
Hi Vlad,

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<stringobject
        { 
            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







0
Vlad
Telerik team
answered on 02 Dec 2009, 06:49 AM
Hi Steve,

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.
0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 08:25 AM
Hi Vlad. That's the one I used and is where it isn't recognizing the IsEnabled.

Steve
0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 08:26 AM
See the attached jpg...
0
Vlad
Telerik team
answered on 02 Dec 2009, 08:31 AM
Hello 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.
0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 09:06 AM
Ok. That now compiles - thanks.

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?
0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 09:12 AM
Hmm I spoke too soon. When I started the site up again, all the grid columns were squished up next to each other and then when I closed the page down, I got an error from the save settings method. The error is in the attached...

It seems that DataMemberBinding is Null.

Steve

0
Vlad
Telerik team
answered on 02 Dec 2009, 09:35 AM
Hi 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.
0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 09:46 AM
Here's more infor. It consistently goes into that 'squished' state when it tries to restore the grid. I unsquished the columns manually and the was no data present (which is why they were squished I guess). It's strange because I have a dataform connected to the same datasource and if I click on a row in the grid (even with no data visible) it changed the row displayed within the dataform. And vice versa. If I moved the dataform to the next row, the grid selected item changed too.

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
0
Vlad
Telerik team
answered on 02 Dec 2009, 10:03 AM
Hello 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.
0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 10:11 AM
Oh I'm sorry - I misunderstood.

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> 
 

0
Steve Y
Top achievements
Rank 2
answered on 02 Dec 2009, 10:17 AM
Here is the whole grid declaration.

                        <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(); 
        } 

0
Vlad
Telerik team
answered on 08 Dec 2009, 10:20 AM
Hello Steve,

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.
0
GPJ
Top achievements
Rank 1
answered on 22 Feb 2010, 10:30 PM
I'm trying to use this class as well .. and when I import it into my project - I get the attached exception.

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?
0
Vlad
Telerik team
answered on 23 Feb 2010, 06:57 AM
Hello GPJ,

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.
0
GPJ
Top achievements
Rank 1
answered on 23 Feb 2010, 03:54 PM
Yes, that was it .. One column has an image in the header, and another has a check box.  Once I remove those UIElements then it starts saving the settings without an exception.

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).

0
Stefan Dobrev
Telerik team
answered on 26 Feb 2010, 11:43 AM
Hello GPJ,

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.
0
GPJ
Top achievements
Rank 1
answered on 05 Mar 2010, 04:04 PM
Hi Stefan,

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
0
Vlad
Telerik team
answered on 11 Mar 2010, 03:04 PM
Hi 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.
0
david mcintyre
Top achievements
Rank 1
answered on 27 May 2010, 07:49 PM

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/>

 

0
Maya
Telerik team
answered on 01 Jun 2010, 04:54 PM
Hello david mcintyre,

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.

 

All the best,
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.
0
david mcintyre
Top achievements
Rank 1
answered on 08 Jun 2010, 10:20 PM
i was experiencing this issue w/ the trial DLLs (RadControls for Silverlight Q1 2010 SP1).  when we purchased the DLLs (RadControls for SL 4 2010 1 0603 DEV hotfix) it worked fine. 
0
Maya
Telerik team
answered on 09 Jun 2010, 04:18 PM
Hello david mcintyre,

 
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.

Greetings,
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.
0
Marlos
Top achievements
Rank 1
answered on 27 Jul 2010, 05:39 PM
Would like to save the layout of the grid view that contains columns of type 
GridViewCheckBoxColumn and GridViewComboBoxColumn?
0
Vlad
Telerik team
answered on 28 Jul 2010, 06:40 AM
Hello,

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
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
0
Pandit Prerna
Top achievements
Rank 1
answered on 02 Aug 2010, 10:29 PM
I used the sample to save the settings and found out that none of the cell templates is being persisted to isolated storage. I have defined few cell templates in my xaml file. Please let me know how to persist them.

0
Vlad
Telerik team
answered on 03 Aug 2010, 06:45 AM
Hi,

 I'm afraid that you cannot persist templates. 

Greetings,
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
0
Pandit Prerna
Top achievements
Rank 1
answered on 03 Aug 2010, 03:35 PM
Hi Vald,

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.
0
Vlad
Telerik team
answered on 03 Aug 2010, 03:45 PM
Hello,

 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);
                            }
                        }
                    }

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
0
Pandit Prerna
Top achievements
Rank 1
answered on 03 Aug 2010, 04:04 PM
Could you please refer me to a sample code that adds templates at runtime? It will be much appreciated.

Thanks
0
Vlad
Telerik team
answered on 04 Aug 2010, 07:35 AM
Hello,

 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
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
0
Bryan Johnson
Top achievements
Rank 1
answered on 26 Oct 2010, 03:48 PM
I am also having a problem with saving/loading settings for radgridview when the grid contains check box columns.  The save/load works fine otherwise.  After putting in some breakpoints in the RadGridViewSettings.cs file I found the problem was occuring during the 'get' of the PropertySetting class when the column being processed was a check box column:

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





0
Vlad
Telerik team
answered on 28 Oct 2010, 03:01 PM
Hi 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
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
0
preeti
Top achievements
Rank 1
answered on 02 Nov 2010, 11:53 AM
hi milan,

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.
0
Timothy
Top achievements
Rank 1
answered on 07 Apr 2011, 05:23 PM
I am recieving this error when I run the project?

Operation not permitted on IsolatedStorageFileStream.
0
loraine
Top achievements
Rank 1
answered on 01 Jun 2011, 02:25 AM
hi!

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
0
Maya
Telerik team
answered on 01 Jun 2011, 07:47 AM
Hello 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.

Greetings,
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
0
Evan
Top achievements
Rank 1
answered on 12 Nov 2011, 02:34 PM
I am anxious to try the load and save but none seem compatible with the current version 2011.2.712.1040 particularly in the area of sort descriptors. And of course pushing the link for "demo" takes me to an empty page.
0
Evan
Top achievements
Rank 1
answered on 12 Nov 2011, 02:34 PM
I am anxious to try the load and save but none seem compatible with the current version 2011.2.712.1040 particularly in the area of sort descriptors. And of course pushing the link for "demo" takes me to an empty page.
0
Maya
Telerik team
answered on 14 Nov 2011, 08:33 AM
Hi Evan,

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.
 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Simon Chan
Top achievements
Rank 1
Answers by
Milan
Telerik team
Simon Chan
Top achievements
Rank 1
Vlad
Telerik team
Steve Y
Top achievements
Rank 2
GPJ
Top achievements
Rank 1
Stefan Dobrev
Telerik team
david mcintyre
Top achievements
Rank 1
Maya
Telerik team
Marlos
Top achievements
Rank 1
Pandit Prerna
Top achievements
Rank 1
Bryan Johnson
Top achievements
Rank 1
preeti
Top achievements
Rank 1
Timothy
Top achievements
Rank 1
loraine
Top achievements
Rank 1
Evan
Top achievements
Rank 1
Share this question
or