void SaveDataGridSettings(object sender, EventArgs e)
        {
            _saveSettingTimer.Stop();
            DataGridSettings settings = new DataGridSettings();

            // get state from grid
            settings.FrozenColumnsCount = c1DataGrid1.FrozenColumnCount;
            foreach (var column in c1DataGrid1.Columns)
            {
                UserColumnSettings columnSetting = new UserColumnSettings();
                columnSetting.ColumnName   = column.Name;
                columnSetting.DisplayIndex = column.DisplayIndex;
                columnSetting.Sort         = new UserColumnSettings.SortGroupState()
                {
                    Direction = column.SortState.Direction, Index = column.SortState.Index
                };
                columnSetting.Group = new UserColumnSettings.SortGroupState()
                {
                    Direction = column.GroupState.Direction, Index = column.GroupState.Index
                };
                columnSetting.Filter = column.FilterState;
                columnSetting.Width  = column.Width.IsAbsolute ? column.Width.Value : -1;

                settings.ColumnSettings.Add(columnSetting);
            }

            // serialize DataGridSettings class to XML
            XmlSerializer ser = CreateSerializer();
            StringWriter  sw  = new StringWriter();

            ser.Serialize(sw, settings);

            // save to user settings
            Properties.Settings.Default.DataGridSettings = sw.ToString();

            // save all settings
            Properties.Settings.Default.Save();
        }
Ejemplo n.º 2
0
        void SaveDataGridSettings(object sender, EventArgs e)
        {
            _saveSettingTimer.Stop();
            DataGridSettings settings = new DataGridSettings();

            // get state from grid
            settings.FrozenColumnsCount = c1DataGrid1.FrozenColumnCount;
            foreach (var column in c1DataGrid1.Columns)
            {
                UserColumnSettings columnSetting = new UserColumnSettings();
                columnSetting.ColumnName = column.Name;
                columnSetting.DisplayIndex = column.DisplayIndex;
                columnSetting.Sort = new UserColumnSettings.SortGroupState() { Direction = column.SortState.Direction, Index = column.SortState.Index };
                columnSetting.Group = new UserColumnSettings.SortGroupState() { Direction = column.GroupState.Direction, Index = column.GroupState.Index };
                columnSetting.Filter = column.FilterState;
                columnSetting.Width = column.Width.IsAbsolute ? column.Width.Value : -1;

                settings.ColumnSettings.Add(columnSetting);
            }

            // serialize DataGridSettings class to XML
            XmlSerializer ser = CreateSerializer();
            StringWriter sw = new StringWriter();
            ser.Serialize(sw, settings);

            // save to user settings
            Properties.Settings.Default.DataGridSettings = sw.ToString();

            // save all settings
            Properties.Settings.Default.Save();
        }