/// <summary>
        /// Saves a UltraExplorerBar using the provided Preferences store.
        /// </summary>
        /// <param name="explorerBar">UltraExplorerBar</param>
        /// <param name="store">Settings</param>
        /// <param name="preferenceId">String. The ID the settings should come from
        /// (multiple sets may exist in the Preference store)</param>
        /// <exception cref="ArgumentNullException">If any of the parameters is null</exception>
        /// <exception cref="InvalidOperationException">If the collection of groups allow duplicate keys
        ///  or any group does not have a unique key</exception>
        internal static void SaveExplorerBar(UltraExplorerBar explorerBar, UiStateSettings store, string preferenceId)
        {
            if (explorerBar == null)
            {
                throw new ArgumentNullException("explorerBar");
            }
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            if (string.IsNullOrEmpty(preferenceId))
            {
                throw new ArgumentNullException("preferenceId");
            }

            if (explorerBar.Groups.AllowDuplicateKeys)
            {
                throw new InvalidOperationException("UltraExplorerBarGroupsCollection must provide unique Keys to support Load/Save settings operations.");
            }

//			explorerBar.SaveAsXml(@"D:\expl.xml");
//			return;

            Preferences prefWriter = store.GetSubnode(preferenceId);

            prefWriter.SetProperty("version", 1);                       // make the impl. extendable

            prefWriter.SetProperty("Location.X", explorerBar.Location.X);
            prefWriter.SetProperty("Location.Y", explorerBar.Location.Y);
            prefWriter.SetProperty("Size.Width", explorerBar.Size.Width);
            prefWriter.SetProperty("Size.Height", explorerBar.Size.Height);

            prefWriter.SetProperty("MaxGroupHeaders", explorerBar.NavigationMaxGroupHeaders);

            // no groups: nothing more to write
            if (explorerBar.Groups.Count == 0)
            {
                prefWriter.SetProperty("groupOrder", null);
                return;
            }

            // build/write the order array:
            prefWriter.SetProperty("groupOrder", GetKeyOrderArray(explorerBar.Groups, ";"));

            for (int i = 0; i < explorerBar.Groups.Count; i++)
            {
                UltraExplorerBarGroup group = explorerBar.Groups[i];
                string key = String.Format("group.{0}", i);
                if (group.Key != null && group.Key.Length > 0)
                {
                    key = String.Format("group.{0}", group.Key);
                }

                if (group.Selected)
                {
                    prefWriter.SetProperty("selected", key);
                }

                prefWriter.SetProperty(String.Format("{0}.Visible", key), group.Visible);
            }
        }
        /// <summary>
        /// Restores a UltraExplorerBar using the provided Preferences.
        /// </summary>
        /// <param name="explorerBar">UltraExplorerBar</param>
        /// <param name="store">Settings</param>
        /// <param name="preferenceId">String. The ID the settings should come from
        /// (multiple sets may exist in the Preference store)</param>
        /// <exception cref="ArgumentNullException">If any of the parameters is null</exception>
        /// <exception cref="InvalidOperationException">If the collection of groups allow duplicate keys
        ///  or any group does not have a unique key</exception>
        internal static void LoadExplorerBar(UltraExplorerBar explorerBar, UiStateSettings store, string preferenceId)
        {
            if (explorerBar == null)
            {
                throw new ArgumentNullException("explorerBar");
            }
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            if (preferenceId == null || preferenceId.Length == 0)
            {
                throw new ArgumentNullException("preferenceId");
            }

            if (explorerBar.Groups.AllowDuplicateKeys)
            {
                throw new InvalidOperationException("UltraExplorerBarGroupsCollection must provide unique Keys to support Load/Save settings operations.");
            }

//			explorerBar.LoadFromXml(@"D:\expl.xml");
//			return;

            Preferences prefReader = store.GetSubnode(preferenceId);
            int         version    = prefReader.GetInt32("version", 0);         // make the impl. extendable

            if (version < 1)
            {
                return;                 // wrong version
            }
            Rectangle dimensions = new Rectangle();

            dimensions.X      = prefReader.GetInt32("Location.X", explorerBar.Location.X);
            dimensions.Y      = prefReader.GetInt32("Location.Y", explorerBar.Location.Y);
            dimensions.Width  = prefReader.GetInt32("Size.Width", explorerBar.Size.Width);
            dimensions.Height = prefReader.GetInt32("Size.Height", explorerBar.Size.Height);

            if (explorerBar.Dock == DockStyle.None && explorerBar.Anchor == AnchorStyles.None)
            {
                explorerBar.Bounds = dimensions;
            }

            explorerBar.NavigationMaxGroupHeaders = prefReader.GetInt32("MaxGroupHeaders", explorerBar.NavigationMaxGroupHeaders);

            // no groups: nothing more to initialize
            if (explorerBar.Groups.Count == 0)
            {
                return;
            }

            // First handle order of groups.
            // build the default order array:
            string defaultOrder = GetKeyOrderArray(explorerBar.Groups, ";");

            // read saved order:
            string    orderArray = prefReader.GetString("groupOrder", defaultOrder);
            ArrayList groupOrder = new ArrayList(orderArray.Split(new char[] { ';' }));

            for (int i = 0; i < groupOrder.Count; i++)
            {
                string key = (string)groupOrder[i];
                if (explorerBar.Groups.Exists(key) &&
                    explorerBar.Groups.IndexOf(key) != i &&
                    i < explorerBar.Groups.Count)
                {                       // restore:
                    UltraExplorerBarGroup group = explorerBar.Groups[key];
                    explorerBar.Groups.Remove(group);
                    explorerBar.Groups.Insert(i, group);
                }
            }

            string selectedGroup = prefReader.GetString("selected", explorerBar.SelectedGroup.Key);

            for (int i = 0; i < explorerBar.Groups.Count; i++)
            {
                UltraExplorerBarGroup group = explorerBar.Groups[i];
                string key = String.Format("group.{0}", i);
                if (group.Key != null && group.Key.Length > 0)
                {
                    key = String.Format("group.{0}", group.Key);
                }

                group.Visible = prefReader.GetBoolean(String.Format("{0}.Visible", key), group.Visible);

                if (selectedGroup == key)
                {
                    group.Selected = true;
                }
            }
        }