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

Persist settings for multiple GridViews in one file

1 Answer 113 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
aborg
Top achievements
Rank 1
aborg asked on 22 Jun 2012, 04:25 PM
I have an app with quite a few different GridViews all of which need to have their settings persisted. Currently, I am creating a file for each GridView to persist the settings between sessions. Is there a way to consolidate this so that more than one gridview can share a settings file? Here is the current code I have for doing persistence:

/// <summary>
    /// Interaction logic for BillingActivityView.xaml
    /// </summary>
    public partial class BillingActivityView
    {
        private static readonly string _appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
 
        private static readonly string _bambooSettingsPath = Path.Combine(_appDataPath, @"Bamboo\Settings");
 
        private static readonly string _testsGridSettingsFilePath = Path.Combine(_bambooSettingsPath, @"TestsGridSettings.bin");
 
        private static readonly string _oldBillClassesGridSettingsFilePath = Path.Combine(_bambooSettingsPath, @"OldBillClassesGridSettings.bin");
 
        private static readonly string _insuranceStatusGridSettingsFilePath = Path.Combine(_bambooSettingsPath, @"InsuranceStatusGridSettings.bin");
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DocumentImageView"/> class.
        /// </summary>
        public BillingActivityView()
        {
            InitializeComponent();
            ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadGridView), new GridViewCustomPropertyProvider());
        }
 
        private void TestsGridView_Initialized(object sender, EventArgs e)
        {
            LoadGridSettings(TestsGridView, _testsGridSettingsFilePath);
        }
 
        private void OldBillClassesGridView_Initialized(object sender, EventArgs e)
        {
            LoadGridSettings(OldBillClassesGridView, _oldBillClassesGridSettingsFilePath);
        }
 
        private void InsuranceStatusGridView_Initialized(object sender, EventArgs e)
        {
            LoadGridSettings(InsuranceStatusGridView, _insuranceStatusGridSettingsFilePath);
        }
 
        public void LoadGridSettings(RadGridView gridView, string settingsPath)
        {
            var manager = new PersistenceManager();
 
            if (!Directory.Exists(_bambooSettingsPath))
            {
                Directory.CreateDirectory(_bambooSettingsPath);
            }
 
            // Load settings if there is something to load
            if (File.Exists(settingsPath))
            {
                try
                {
                    var fileStream = File.OpenRead(settingsPath);
                    manager.Load(gridView, fileStream);
                    fileStream.Close();
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message, "BILLINGACTIVITYVIEW");
                }
            }
        }
 
        public void PersistAllGridSettings()
        {
            PersistGridSettings(TestsGridView, _testsGridSettingsFilePath);
            PersistGridSettings(OldBillClassesGridView, _oldBillClassesGridSettingsFilePath);
            PersistGridSettings(InsuranceStatusGridView, _insuranceStatusGridSettingsFilePath);
        }
 
        public void PersistGridSettings(RadGridView gridView, string settingsPath)
        {
            var manager = new PersistenceManager();
            var stream = manager.Save(gridView);
 
            using (var fileStream = File.Create(settingsPath))
            {
                stream.CopyTo(fileStream);
            }
        }
    }

1 Answer, 1 is accepted

Sort by
0
Lancelot
Top achievements
Rank 1
answered on 26 Jun 2012, 09:08 PM
Hi Brian,

  This would be the perfect opportunity for you to leverage the power and flexibility of the RadPersistenceFramework. This link will bring you the Getting Started page in the help documentation. With just a couple lines of code you can persist the settings of all your RadGridView instances.

Good Luck!
Lancelot
Tags
PersistenceFramework
Asked by
aborg
Top achievements
Rank 1
Answers by
Lancelot
Top achievements
Rank 1
Share this question
or