Example #1
0
        private void RowColBackground()
        {
            if (RowColumnBg.SelectedItem != null)
            {
                GridBaseStyle basestyle = new GridBaseStyle();
                basestyle.Name = "Applied Background";
                basestyle.StyleInfo = new GridStyleInfo() { Background = new SolidColorBrush(GridUtil.GetXamlConvertedValue<Color>(RowColumnBg.SelectedItem.ToString())) };
                grid.Model.BaseStylesMap.Add(basestyle);
                try
                {
                    var index = Convert.ToInt32(ColumnRowIndex.Text);

                    this.grid.InvalidateCells();
                    if (ColumnRowIndex.Text != "")
                    {
                        for (int i = 1; i < grid.Model.ColumnCount; i++)
                        {
                            grid.Model[index, i].BaseStyle = "Applied Background";
                            grid.Model.InvalidateCell(new RowColumnIndex(index, i));
                        }
                        for (int i = 1; i < grid.Model.RowCount; i++)
                        {
                            grid.Model[i, index].BaseStyle = "Applied Background";
                            grid.Model.InvalidateCell(new RowColumnIndex(i, index));
                        }
                    }
                }
                catch
                {
                    ColumnRowIndex.Text = " ";
                }
            }
        }
Example #2
0
        private void InitializeGrid()
        {
            #region CellStyleGridControl

            gridControl1.Model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;

            GridFontInfo boldFont = new GridFontInfo();
            boldFont.Bold      = true;
            boldFont.Size      = 11;
            boldFont.Underline = true;

            int rowIndex = 2;
            int colIndex = 1;

            gridControl1.Rows.DefaultSize += 2;
            int boldfontRowHeight = gridControl1.Rows.DefaultSize + 6;

            gridControl1.Model.Options.ControllerOptions         = GridControllerOptions.All;
            gridControl1.Model.Options.DataObjectConsumerOptions = GridDataObjectConsumerOptions.All;

            GridStyleInfo standard  = gridControl1.BaseStylesMap["Standard"].StyleInfo;
            GridStyleInfo header    = gridControl1.BaseStylesMap["Header"].StyleInfo;
            GridStyleInfo rowHeader = gridControl1.BaseStylesMap["Row Header"].StyleInfo;
            GridStyleInfo colHeader = gridControl1.BaseStylesMap["Column Header"].StyleInfo;

            header.Interior    = new BrushInfo(SystemColors.Control);
            rowHeader.Interior = new BrushInfo(SystemColors.Control);

            standard.Font.Facename = "Arial"; //"Helvetica";
            header.Enabled         = false;

            gridControl1.Model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text = "Interior";
            gridControl1[rowIndex, 1].Font = boldFont;

            boldfontRowHeight = gridControl1.RowHeights[rowIndex];
            rowIndex++;

            colIndex = 1;
            foreach (Color color in new Color[] {
                Color.Black,
                Color.Red,
                Color.Blue,
                Color.Green,
                Color.Yellow,
                Color.DimGray
            })
            {
                gridControl1[rowIndex, colIndex].Interior = new BrushInfo(color);
                colIndex++;
            }
            rowIndex++;
            colIndex = 1;
            foreach (PatternStyle pattern in new PatternStyle[] {
                PatternStyle.LightVertical,
                PatternStyle.DarkDownwardDiagonal,
                PatternStyle.DashedHorizontal,
                PatternStyle.DottedDiamond,
                PatternStyle.SmallCheckerBoard,
                PatternStyle.SmallGrid
            })
            {
                gridControl1[rowIndex, colIndex].Interior = new BrushInfo(pattern, Color.Black, Color.White);
                colIndex++;
            }
            rowIndex++;
            colIndex = 1;
            foreach (GradientStyle pattern in new GradientStyle[]
            {
                GradientStyle.BackwardDiagonal,
                GradientStyle.ForwardDiagonal,
                GradientStyle.PathEllipse,
                GradientStyle.PathRectangle,
                GradientStyle.Vertical,
                GradientStyle.Horizontal
            })
            {
                gridControl1[rowIndex, colIndex].Interior           = new BrushInfo(pattern, Color.FromArgb(0xde, 0x64, 0x13), Color.Black); //Color.Yellow, Color.Blue);
                gridControl1[rowIndex, colIndex].CellAppearance     = GridCellAppearance.Raised;
                gridControl1[rowIndex + 1, colIndex].Interior       = new BrushInfo(pattern, Color.FromArgb(0x82, 0x2e, 0x1b), Color.White); //Color.Red, Color.White);
                gridControl1[rowIndex + 1, colIndex].CellAppearance = GridCellAppearance.Sunken;
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "Font";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int size in new int[] {
                6,
                7,
                8,
                10,
                12,
                14
            })
            {
                gridControl1[rowIndex, colIndex].Font.Size = size;
                gridControl1[rowIndex, colIndex].Text      = size.ToString();
                colIndex++;
            }
            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex));

            rowIndex++;
            colIndex = 1;
            foreach (FontStyle fontStyle in new FontStyle[]
            {
                FontStyle.Bold,
                FontStyle.Italic,
                FontStyle.Regular,
                FontStyle.Strikeout,
                FontStyle.Underline,
                FontStyle.Bold | FontStyle.Italic | FontStyle.Regular
            })
            {
                gridControl1[rowIndex, colIndex].Font.FontStyle = fontStyle;
                gridControl1[rowIndex, colIndex].Text           = System.Enum.Format(typeof(FontStyle), fontStyle, "G");
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "TextColor";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (Color color in new Color[] {
                Color.Black,
                Color.Red,
                Color.Blue,
                Color.Green,
                Color.Yellow,
                Color.DimGray
            })
            {
                gridControl1[rowIndex, colIndex].TextColor = color;
                gridControl1[rowIndex, colIndex].Text      = ColorConvert.ColorToString(color, true);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "Borders";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;
            colIndex = 1;

            foreach (GridBorder border in new GridBorder[] {
                new GridBorder(GridBorderStyle.Solid, Color.Black),
                new GridBorder(GridBorderStyle.Dotted, Color.Red),
                new GridBorder(GridBorderStyle.DashDot, Color.Black),
                new GridBorder(GridBorderStyle.DashDotDot, Color.Red),
                new GridBorder(GridBorderStyle.Dashed, Color.Black, GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Dotted, Color.Red, GridBorderWeight.Medium)
            })
            {
                gridControl1[rowIndex, colIndex].Borders.Bottom = border;
                gridControl1[rowIndex, colIndex].Borders.Right  = border;
                gridControl1[rowIndex, colIndex].Text           = border.ToString();
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (GridBorder border in new GridBorder[] {
                new GridBorder(GridBorderStyle.Dashed, Color.Black, GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Dotted, Color.Red, GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.DashDot, Color.Black, GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.DashDotDot, Color.Red, GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Solid, Color.Black, GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Solid, Color.Red, GridBorderWeight.Medium)
            })
            {
                gridControl1[rowIndex, colIndex].Borders.Bottom = border;
                gridControl1[rowIndex, colIndex].Borders.Right  = border;
                gridControl1[rowIndex, colIndex].Text           = border.ToString();
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            gridControl1[rowIndex, 1].Text    = "Orientation";
            gridControl1[rowIndex, 1].Font    = boldFont;
            gridControl1.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int orientation in new int[]
            {
                0,
                45,
                60,
                90,
                180,
                -90
            })
            {
                GridStyleInfo style1 = gridControl1[rowIndex, colIndex];
                // style1 is a direct reference to gridControl1[rowIndex, colIndex];
                // changes will be propagated back to GridData
                style1.HorizontalAlignment = GridHorizontalAlignment.Center;
                style1.VerticalAlignment   = GridVerticalAlignment.Middle;
                GridFontInfo font = style1.Font;
                font.Orientation = orientation;
                font.Bold        = true;
                style1.Text      = "Angle = " + font.Orientation.ToString();
                colIndex++;
            }

            gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Row(rowIndex));

            rowIndex++;
            rowIndex++;
            colIndex = 1;

            gridControl1.CurrentCell.MoveTo(2, 2);

            this.gridControl1.DefaultRowHeight = 18;
            this.gridControl1.DefaultColWidth  = 70;

            this.gridControl1.DefaultGridBorderStyle = GridBorderStyle.Solid;
            #endregion

            #region StyleObject Grid
            //change the header's BackColor
            gridControl2.BaseStylesMap["Header"].StyleInfo.BackColor     = Color.FromArgb(238, 240, 246);
            gridControl2.BaseStylesMap["Row Header"].StyleInfo.BackColor = Color.FromArgb(238, 240, 246);

            //add a new basestyle
            gridBaseStyle1 = new GridBaseStyle("BackColorTest", false);
            gridControl2.BaseStylesMap["BackColorTest"].StyleInfo.BackColor = Color.SkyBlue;


            #endregion
        }