How To Save and load settings with RadGridView for Silverlight?

50 posts, 0 answers
  1. Simon Chan
    Simon Chan avatar
    13 posts
    Member since:
    Jul 2009

    Posted 18 Sep 2009 Link to this post

    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



  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 22 Sep 2009 Link to this post

    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.
  3. DevCraft banner
  4. Simon Chan
    Simon Chan avatar
    13 posts
    Member since:
    Jul 2009

    Posted 23 Sep 2009 Link to this post

    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

     


  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Sep 2009 Link to this post

    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.
  6. Simon Chan
    Simon Chan avatar
    13 posts
    Member since:
    Jul 2009

    Posted 24 Sep 2009 Link to this post

    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
  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Sep 2009 Link to this post

    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.
  8. Simon Chan
    Simon Chan avatar
    13 posts
    Member since:
    Jul 2009

    Posted 24 Sep 2009 Link to this post

    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
      

     

  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 25 Sep 2009 Link to this post

    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.
  10. Simon Chan
    Simon Chan avatar
    13 posts
    Member since:
    Jul 2009

    Posted 25 Sep 2009 Link to this post

    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
  11. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Oct 2009 Link to this post

    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.
  12. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 01 Dec 2009 Link to this post

    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







  13. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Dec 2009 Link to this post

    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.
  14. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

    Hi Vlad. That's the one I used and is where it isn't recognizing the IsEnabled.

    Steve
  15. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

    See the attached jpg...
  16. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Dec 2009 Link to this post

    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.
  17. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

    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?
  18. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

    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

  19. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Dec 2009 Link to this post

    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.
  20. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

    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
  21. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Dec 2009 Link to this post

    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.
  22. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

    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> 
     

  23. Steve Y
    Steve Y avatar
    115 posts
    Member since:
    Sep 2008

    Posted 02 Dec 2009 Link to this post

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

  24. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Dec 2009 Link to this post

    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.
  25. GPJ
    GPJ avatar
    31 posts
    Member since:
    Oct 2008

    Posted 22 Feb 2010 Link to this post

    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?
  26. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 23 Feb 2010 Link to this post

    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.
  27. GPJ
    GPJ avatar
    31 posts
    Member since:
    Oct 2008

    Posted 23 Feb 2010 Link to this post

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

  28. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 26 Feb 2010 Link to this post

    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.
  29. GPJ
    GPJ avatar
    31 posts
    Member since:
    Oct 2008

    Posted 05 Mar 2010 Link to this post

    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
  30. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Mar 2010 Link to this post

    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.
  31. david mcintyre
    david mcintyre avatar
    31 posts
    Member since:
    Mar 2010

    Posted 27 May 2010 Link to this post

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

     

Back to Top
DevCraft banner