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

Save GridView Style Settings

14 Answers 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vincent
Top achievements
Rank 1
Vincent asked on 02 Jun 2011, 02:11 AM
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!

14 Answers, 1 is accepted

Sort by
0
aubrey
Top achievements
Rank 1
answered on 02 Jun 2011, 09:30 AM
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 :')  
0
Ivan Ivanov
Telerik team
answered on 02 Jun 2011, 12:41 PM
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
0
Vincent
Top achievements
Rank 1
answered on 02 Jun 2011, 02:32 PM
Hi Telerik! 
Can you give a code of using Memory Stream instead of Isolated Storage? :)
0
Vincent
Top achievements
Rank 1
answered on 02 Jun 2011, 02:50 PM
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!
0
Ivan Ivanov
Telerik team
answered on 02 Jun 2011, 03:09 PM
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
0
Vincent
Top achievements
Rank 1
answered on 02 Jun 2011, 03:22 PM
Hi Ivan!

Ahhmm, what is that "object" that you pass as a second parameter in the write object? 
0
Ivan Ivanov
Telerik team
answered on 02 Jun 2011, 03:32 PM
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
0
Vincent
Top achievements
Rank 1
answered on 02 Jun 2011, 03:34 PM
Ahhh... I see...

Thanks! I will try to apply all your ideas... :)
0
Vincent
Top achievements
Rank 1
answered on 03 Jun 2011, 01:59 AM
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
                {
                    //
                }
0
Vincent
Top achievements
Rank 1
answered on 03 Jun 2011, 02:09 AM
Hi Telerik!

My main concern is how to export RadGridViewSettings into Memory stream.... Can you give me code of this? :)
0
loraine
Top achievements
Rank 1
answered on 03 Jun 2011, 02:09 AM
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)?
0
aubrey
Top achievements
Rank 1
answered on 03 Jun 2011, 02:35 AM
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 :')
0
Accepted
Ivan Ivanov
Telerik team
answered on 03 Jun 2011, 10:28 AM
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
0
Prince
Top achievements
Rank 1
answered on 13 Feb 2012, 12:47 PM
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);

 
Tags
GridView
Asked by
Vincent
Top achievements
Rank 1
Answers by
aubrey
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Vincent
Top achievements
Rank 1
loraine
Top achievements
Rank 1
Prince
Top achievements
Rank 1
Share this question
or