/// <summary>
        /// Save current settings from the passed grid to the passed GridSettings
        /// </summary>
        /// <param name="settings">The GridSettings that will have the settings saved to it</param>
        /// <param name="grid">The UltraGrid from which the settings will be saved</param>
        public static void SaveSettings(GridSettings settings, UltraGrid grid)
        {
            SortedList <Pair <int, int>, ColumnSettings> colSorts = new SortedList <Pair <int, int>, ColumnSettings>();

            settings.GroupByBoxVisible = !grid.DisplayLayout.GroupByBox.Hidden;
            settings.Columns           = new Dictionary <Pair <int, string>, ColumnSettings>();
            ColumnSettings colSettings;

            foreach (UltraGridBand band in grid.DisplayLayout.Bands)
            {
                foreach (UltraGridColumn col in band.Columns)
                {
                    colSettings = new ColumnSettings(band.Index, col.Key, col.Header.VisiblePosition, col.Header.Fixed, col.Width, col.Hidden);
                    colSettings.SetColumnSort(band.SortedColumns.IndexOf(col), col.SortIndicator, col.IsGroupByColumn);
                    settings.Columns.Add(new Pair <int, string>(band.Index, col.Key), colSettings);
                }
            }
        }
        /// <summary>
        /// Apply the passed GridSettings to the passed UltraGrid
        /// </summary>
        /// <param name="settings">The GridSettings to apply to the grid</param>
        /// <param name="grid">The UltraGrid that will have the settings applied to it</param>
        /// <param name="hideExcludeFromColumnChooserColumns">Hide all columns from the grid that do not appear in the column chooser</param>
        public static void ApplySettingsToGrid(GridSettings settings, UltraGrid grid, bool hideExcludeFromColumnChooserColumns)
        {
            UltraGridColumn col;
            SortedList <Pair <int, int>, ColumnSettings> colSorts = new SortedList <Pair <int, int>, ColumnSettings>();

            grid.DisplayLayout.GroupByBox.Hidden = !settings.GroupByBoxVisible;
            foreach (ColumnSettings colSettings in settings.Columns.Values)
            {
                if (grid.DisplayLayout.Bands.Count > colSettings.Band &&
                    grid.DisplayLayout.Bands[colSettings.Band].Columns.IndexOf(colSettings.Key) > -1)
                {
                    col = grid.DisplayLayout.Bands[colSettings.Band].Columns[colSettings.Key];
                    col.Header.VisiblePosition = colSettings.Position;
                    col.Header.Fixed           = colSettings.Fixed;
                    col.Width = colSettings.Width;
                    // don't redisplay a column that is now permanently hidden
                    if (hideExcludeFromColumnChooserColumns)
                    {
                        col.Hidden = colSettings.Hidden || col.ExcludeFromColumnChooser == ExcludeFromColumnChooser.True;
                    }
                    else
                    {
                        col.Hidden = colSettings.Hidden;
                    }
                    col.SortIndicator = SortIndicator.None;
                    if (colSettings.SortDirection != SortIndicator.None)
                    {
                        colSorts.Add(new Pair <int, int>(colSettings.Band, colSettings.SortPosition), colSettings);
                    }
                }
            }

            // Apply the sorts in order
            foreach (KeyValuePair <Pair <int, int>, ColumnSettings> colSort in colSorts)
            {
                grid.DisplayLayout.Bands[colSort.Key.First].SortedColumns.Add(
                    grid.DisplayLayout.Bands[colSort.Key.First].Columns[colSort.Value.Key],
                    colSort.Value.SortDirection == SortIndicator.Descending ? true : false,
                    colSort.Value.IsGroupByColumn);
            }
        }
        /// <summary>
        /// Compare to the passed GridSettings object and make sure all internal values are equal
        /// </summary>
        /// <param name="obj">a GridSettings object to compare against</param>
        /// <returns>true if a GridSettings object is passed and all settings match otherwise false</returns>
        public override bool Equals(object obj)
        {
            if (obj is GridSettings)
            {
                GridSettings settings = (GridSettings)obj;
                if (groupbyBoxVisible != settings.GroupByBoxVisible ||
                    columns.Count != settings.columns.Count)
                {
                    return(false);
                }
                else
                {
                    ColumnSettings columnSettings;
                    foreach (KeyValuePair <Pair <int, string>, ColumnSettings> colSettings in columns)
                    {
                        if (settings.Columns.TryGetValue(colSettings.Key, out columnSettings))
                        {
                            if (!colSettings.Value.Equals(columnSettings))
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
            }
            else
            {
                return(base.Equals(obj));
            }
        }
 /// <summary>
 /// Apply the passed GridSettings to the passed UltraGrid
 /// </summary>
 /// <param name="settings">The GridSettings to apply to the grid</param>
 /// <param name="grid">The UltraGrid that will have the settings applied to it</param>
 public static void ApplySettingsToGrid(GridSettings settings, UltraGrid grid)
 {
     ApplySettingsToGrid(settings, grid, false);
 }