Example #1
0
        public static string ReadGridSettings(RadGrid grid)
        {
            object[] gridSettings = new object[4];

            //Save groupBy
            GridGroupByExpressionCollection groupByExpressions = grid.MasterTableView.GroupByExpressions;

            object[] groupExpressions = new object[groupByExpressions.Count];

            int count = 0;

            foreach (GridGroupByExpression expression in groupByExpressions)
            {
                groupExpressions[count] = ((IStateManager)expression).SaveViewState();
                count++;
            }

            gridSettings[0] = groupExpressions;

            //Save sort expressions
            gridSettings[1] = ((IStateManager)grid.MasterTableView.SortExpressions).SaveViewState();

            //Save columns order
            int columnsLength = grid.MasterTableView.Columns.Count +
                                grid.MasterTableView.AutoGeneratedColumns.Length;

            Pair[] columnOrder = new Pair[columnsLength];

            ArrayList allColumns = new ArrayList(columnsLength);

            allColumns.AddRange(grid.MasterTableView.Columns);
            allColumns.AddRange(grid.MasterTableView.AutoGeneratedColumns);

            int i = 0;

            foreach (GridColumn column in allColumns)
            {
                Pair p = new Pair();
                p.First  = column.OrderIndex;
                p.Second = column.HeaderStyle.Width;

                columnOrder[i] = p;

                i++;
            }

            gridSettings[2] = columnOrder;

            //Save filter expression
            gridSettings[3] = (object)grid.MasterTableView.FilterExpression;

            LosFormatter formatter = new LosFormatter();

            StringWriter writer = new StringWriter();

            formatter.Serialize(writer, gridSettings);

            return(writer.ToString());
        }
Example #2
0
        public static void LoadGridSettings(RadGrid grid, string data)
        {
            if (data == null || data.Trim() == "")
            {
                ClearGridSettings(grid);
                return;
            }

            try
            {
                ClearGridSettings(grid);
                LosFormatter formatter = new LosFormatter();
                StringReader reader    = new StringReader(data);

                object[] gridSettings = (object[])formatter.Deserialize(reader);

                //Load groupBy
                GridGroupByExpressionCollection groupByExpressions = grid.MasterTableView.GroupByExpressions;
                groupByExpressions.Clear();

                object[] groupExpressionsState = (object[])gridSettings[0];

                int count = 0;
                foreach (object obj in groupExpressionsState)
                {
                    GridGroupByExpression expression = new GridGroupByExpression();
                    ((IStateManager)expression).LoadViewState(obj);
                    groupByExpressions.Add(expression);
                    count++;
                }

                //Load sort expressions
                grid.MasterTableView.SortExpressions.Clear();
                ((IStateManager)grid.MasterTableView.SortExpressions).LoadViewState(gridSettings[1]);

                //Load columns order
                int columnsLength = grid.MasterTableView.Columns.Count +
                                    grid.MasterTableView.AutoGeneratedColumns.Length;

                Pair[] columnOrder = (Pair[])gridSettings[2];

                if (columnsLength == columnOrder.Length)
                {
                    ArrayList allColumns = new ArrayList(columnsLength);

                    allColumns.AddRange(grid.MasterTableView.Columns);
                    allColumns.AddRange(grid.MasterTableView.AutoGeneratedColumns);

                    int i = 0;
                    foreach (GridColumn column in allColumns)
                    {
                        column.OrderIndex = (int)columnOrder[i].First;
                        Unit unit = (Unit)columnOrder[i].Second;
                        column.HeaderStyle.Width = unit.IsEmpty ? new Unit(200, UnitType.Pixel) : unit;
                        i++;
                    }
                }
                //Load filter expression
                //grid.MasterTableView.FilterExpression = (string)gridSettings[3];
            }
            catch (Exception)
            {
                ClearGridSettings(grid);
            }
        }