Save GridView Style Settings

15 posts, 1 answers
  1. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 01 Jun 2011 Link to this post

    Hi Telerik!

    I have seen a code in saving the gridview Settings like saving how you group and sort the gridview. But my concern is, I want to save the settings in the database so that when I access data in database, I will just pass the setting as a parameter and then gridview setting is then applied. So, is there a way to save and retrieve gridview setting using database? :)

    Thanks!
  2. aubrey
    aubrey avatar
    27 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Good day Telerik Team,

      i've tried your sample demo and it works fine...

    Am having the same concern with vincent. i want to save gridview setting(s) to database, and retrieve those gridview setting(s) and put it to RadComboBox, the user may choose what gridview settings he wants to apply from the combobox list of gridview settings..

    Is it possible to save Gridview setting(s) to Database? if there is, can you give us sample demos on this matter?

    hoping to hear from you sooner..

    thanks

    Aubrey :')  
  3. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1218 posts

    Posted 02 Jun 2011 Link to this post

    Hello aubrey,

    Please, refer to this example. The illustrated approach supposes that you want to export these settings into an isolated storage file. But instead of using an IsolatedStorageFileStream, you may export them through a simple MemoryStream, which you will be able to easily convert to a string like this:

    System.Text.Encoding.Unicode.GetString(myMemoryStream.ToArray());
    The reverse procedure should be analogical.

    All the best,
    Ivan Ivanov
    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
  4. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi Telerik! 
    Can you give a code of using Memory Stream instead of Isolated Storage? :)
  5. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi! I am just a newbie here!
    How to convert this IsolatedStorageFile to Memory Stream as you have suggested in order to store it easily to the database....

    using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(PersistID, FileMode.Open, file))
                            {
                                if (stream.Length > 0)
                                {
                                    RadGridViewApplicationSettings loaded = (RadGridViewApplicationSettings) serializer.ReadObject(stream);


                                    FrozenColumnCount = loaded.FrozenColumnCount;

                                    ColumnSettings.Clear();
                                    foreach (ColumnSetting cs in loaded.ColumnSettings)
                                    {
                                        ColumnSettings.Add(cs);
                                    }


                                    FilterSettings.Clear();
                                    foreach (FilterSetting fs in loaded.FilterSettings)
                                    {
                                        FilterSettings.Add(fs);
                                    }

                                    GroupSettings.Clear();
                                    foreach (GroupSetting gs in loaded.GroupSettings)
                                    {
                                        GroupSettings.Add(gs);
                                    }

                                    SortSettings.Clear();
                                    foreach (SortSetting ss in loaded.SortSettings)
                                    {
                                        SortSettings.Add(ss);
                                    }
                                }
                            }
                        }


     public void Reset()
                {
                    try
                    {
                        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            file.DeleteFile(PersistID);
                        }
                    }
                    catch
                    {
                        //
                    }
                }


                public void Save()
                {
                    try
                    {
                        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(PersistID, FileMode.Create, file))
                            {
                                serializer.WriteObject(stream, this);
                            }
                        }
                    }
                    catch
                    {
                        //
                    }
                }


    ------- Pls. answer me. Thanks!
  6. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1218 posts

    Posted 02 Jun 2011 Link to this post

    Hello Vincent,

    Do not use the isolated storage at all. Just try passing an instance of MemoryStream as the first argument of WriteObject(Stream, Object). Then convert this MemoryStream to a byte array and then extract the respective string, utilizing the approach that I have illustrated below.

    Greetings,
    Ivan Ivanov
    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
  7. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi Ivan!

    Ahhmm, what is that "object" that you pass as a second parameter in the write object? 
  8. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1218 posts

    Posted 02 Jun 2011 Link to this post

    Hi Vincent,

    It is the current RadGridViewApplicationSettings instance.

    Greetings,
    Ivan Ivanov
    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
  9. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Ahhh... I see...

    Thanks! I will try to apply all your ideas... :)
  10. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi Telerik!

    I am a bit confused...
    Can you try to convert this IsolatedFIleStorage code to Memory Stream plzz....... 
    try
                    {
                        using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
                        {
                            using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(PersistID, FileMode.Create, file))
                            {
                                serializer.WriteObject(stream, this);
                            }
                        }
                    }
                    catch
                    {
                        //
                    }
  11. Vincent
    Vincent avatar
    34 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi Telerik!

    My main concern is how to export RadGridViewSettings into Memory stream.... Can you give me code of this? :)
  12. loraine
    loraine avatar
    30 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi Ivan!

    i am also having the same issue. can you please show a code snippet on how to store the settings to the local drive (ex: my documents)?
  13. aubrey
    aubrey avatar
    27 posts
    Member since:
    Apr 2011

    Posted 02 Jun 2011 Link to this post

    Hi Ivan,

    am sorry to bother you again. I've tried your code here:
    using (MemoryStream mystream = new MemoryStream())
    {
      serializer.WriteObject(mystream, settings);
      System.Text.Encoding.Unicode.GetString(mystream.ToArray());
    }
    but there's an error:
    Error 1 'System.Text.Encoding.GetString(byte[])' is inaccessible due to its protection level

    am confused if i get ur idea right. Y_Y

    can you give me a code snippet how to accomplish this. 

    hoping for your reply 
    Aubrey :')
  14. Answer
    Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1218 posts

    Posted 03 Jun 2011 Link to this post

    Hello,

    I have modified the demo's save logic to work with a MemoryStream and to convert the settings to string. I have attached the project for your reference. As for the question concerning saving the settings on the local file system, you should have an OOB application, with elevated permissions set, in order to be permitted to do this.

    Regards,
    Ivan Ivanov
    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
  15. Prince
    Prince avatar
    2 posts
    Member since:
    Jun 2012

    Posted 13 Feb 2012 Link to this post

    I have the string settings ,, i want to convert it back to memory stream and apply to radgridview settings,.
    I have a code bt im getting an error on converting e string to memorystrem.
     string gridSettings= setting.gridSettings;

                       // convert string to stream
                       byte[] byteArray = Encoding.Unicode.GetBytes(gridSettings );
                       
                       MemoryStream stream = new MemoryStream(byteArray);

     
Back to Top