Exemplo n.º 1
0
        private void ModifyFontsAndOtherStyleProperties(GridStyleInfo sourceStyle1, GridStyleInfo targetStyle)
        {
            GridStyleInfo sourceStyle = new GridStyleInfo();

            sourceStyle.CopyFrom(sourceStyle1);

            GridFontInfo sourceStyleFont = sourceStyle.GetValue(GridStyleInfoStore.FontProperty) as GridFontInfo;
            GridFontInfo targetStyleFont = targetStyle.GetValue(GridStyleInfoStore.FontProperty) as GridFontInfo;

            if (sourceStyleFont.HasFontFamily)
            {
                targetStyleFont.FontFamily = sourceStyleFont.FontFamily;
            }
            if (sourceStyleFont.HasFontSize)
            {
                targetStyleFont.FontSize = sourceStyleFont.FontSize;
            }
            if (sourceStyleFont.HasFontStretch)
            {
                targetStyleFont.FontStretch = sourceStyleFont.FontStretch;
            }
            if (sourceStyleFont.HasFontStyle)
            {
                targetStyleFont.FontStyle = sourceStyleFont.FontStyle;
            }
            if (sourceStyleFont.HasFontWeight)
            {
                targetStyleFont.FontWeight = sourceStyleFont.FontWeight;
            }
            sourceStyle.ResetFont();
            targetStyle.ModifyStyle(sourceStyle, Syncfusion.Windows.Styles.StyleModifyType.Override);
        }
Exemplo n.º 2
0
        public static void SetupGridModel(GridModel model)
        {
            GridFactoryProvider.Init(new GridCellModelFactory());
            model.Options.AlphaBlendSelectionColor = Color.FromArgb(64, SystemColors.Highlight);
            model.Options.AllowSelection           = GridSelectionFlags.Any;

            //model.BaseStylesMap.RegisterStandardStyles();
            model.CommandStack.Enabled      = true;
            model.QueryCellModel           += new GridQueryCellModelEventHandler(ModelQueryCellModel);
            model.OperationFeedbackListener = new DelayedStatusDialog(model);

            model.BeginInit();
            model.RowCount                          = 1000;
            model.ColCount                          = 100;
            model.Rows.DefaultSize                  = 19;
            model.Cols.DefaultSize                  = 65;
            model.RowHeights[0]                     = 21;
            model.ColWidths[0]                      = 35;
            model.ColWidths[3]                      = 85;
            model.Options.ControllerOptions         = GridControllerOptions.All;
            model.Options.DataObjectConsumerOptions = GridDataObjectConsumerOptions.All;


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

            model.Properties.GridLineColor = Color.FromArgb(65, 57, 73, 122);

            GridFontInfo boldFont = new GridFontInfo();

            boldFont.Bold     = true;
            boldFont.Size     = 11;
            boldFont.Facename = "Helvetica";

            standard.TextColor = Color.FromArgb(0, 21, 84);

            GridStyleInfo boldFontStyle = new GridStyleInfo();

            boldFontStyle.TextColor = Color.FromArgb(238, 122, 3);
            boldFontStyle.Font      = boldFont;

            header.Interior    = new BrushInfo(GradientStyle.Vertical, Color.FromArgb(65, 238, 234, 216), Color.FromArgb(65, 203, 199, 184));
            rowHeader.Interior = new BrushInfo(GradientStyle.Horizontal, Color.FromArgb(65, 238, 234, 216), Color.FromArgb(65, 203, 199, 184));

            bool showImageList = false;

            if (showImageList)
            {
                ImageList imageList = new ImageList();
                imageList.Images.Add(SystemIcons.Warning.ToBitmap());
                imageList.Images.Add(SystemIcons.Application.ToBitmap());
                imageList.Images.Add(SystemIcons.Asterisk.ToBitmap());
                imageList.Images.Add(SystemIcons.Error.ToBitmap());
                imageList.Images.Add(SystemIcons.Exclamation.ToBitmap());
                imageList.Images.Add(SystemIcons.Hand.ToBitmap());
                imageList.Images.Add(SystemIcons.Information.ToBitmap());
                imageList.Images.Add(SystemIcons.Question.ToBitmap());
                standard.ImageList = imageList;
            }

            ArrayList USStates = new ArrayList();

            USStates.Add(new USState("Alabama", "AL", 0));
            USStates.Add(new USState("Washington", "WA", 1));
            USStates.Add(new USState("West Virginia", "WV", 2));
            USStates.Add(new USState("Wisconsin", "WI", 3));
            USStates.Add(new USState("Wyoming", "WY", 4));
            USStates.Add(new USState("XAlabama", "AAL", 5));
            USStates.Add(new USState("XWashington", "AWA", 6));
            USStates.Add(new USState("XWest Virginia", "AWV", 1));
            USStates.Add(new USState("XWisconsin", "AWI", 2));
            USStates.Add(new USState("XWyoming", "AWY", 3));
            USStates.Add(new USState("QAlabama", "BAL", 4));
            USStates.Add(new USState("QWashington", "BWA", 5));
            USStates.Add(new USState("QWest Virginia", "BWV", 6));
            USStates.Add(new USState("QWisconsin", "BWI", 0));
            USStates.Add(new USState("QWyoming", "BWY", 1));

            standard.DataSource    = USStates;
            standard.DisplayMember = "LongName";
            standard.ValueMember   = "ShortName";

            Type type = typeof(Bitmap);

            System.IO.Stream stream   = typeof(SampleGrid).Module.Assembly.GetManifestResourceStream(ApplicationMain.manifestNamespace + "logo_105_65.bmp");
            Bitmap           bm       = new Bitmap(stream);
            ImageList        logoList = new ImageList();

            logoList.Images.Add(bm);
            logoList.ImageSize  = bm.Size;
            logoList.ColorDepth = ColorDepth.Depth32Bit;

            int rowIndex = 2;
            int colIndex = 1;

            int boldfontRowHeight = 0;


            model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;


            model.CoveredRanges.Add(GridRangeInfo.Cells(2, 2, 4, 4));

            model[2, 2].Text                = "Grid Demo";
            model[2, 2].Font.Bold           = true;
            model[2, 2].Font.Size           = 16;
            model[2, 2].HorizontalAlignment = GridHorizontalAlignment.Center;
            model[2, 2].VerticalAlignment   = GridVerticalAlignment.Middle;
            model[2, 2].CellType            = "Static";
            model[2, 2].Borders.All         = new GridBorder(GridBorderStyle.Solid, Color.FromArgb(65, 238, 122, 3));
            model[2, 2].Interior            = new BrushInfo(GradientStyle.PathEllipse, Color.FromArgb(65, 57, 73, 122), Color.FromArgb(65, 237, 240, 247));
            rowIndex += 5;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Interior";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights.ResizeToFit(GridRangeInfo.Cell(rowIndex, 1), GridResizeToFitOptions.ResizeCoveredCells | GridResizeToFitOptions.NoShrinkSize);
            boldfontRowHeight = model.RowHeights[rowIndex];
            rowIndex++;

            colIndex = 1;
            foreach (int index in new int[] {
                1,
                2,
                3,
                4,
                5,
                6,
            })
            {
                model[rowIndex, colIndex].ImageIndex = index;
                colIndex++;
            }
            rowIndex++;


            colIndex = 1;
            foreach (Color color1 in new Color[] {
                Color.FromArgb(65, 0, 0, 51),
                Color.FromArgb(65, 252, 172, 38),
                Color.FromArgb(65, 33, 67, 126),
                Color.FromArgb(65, 102, 110, 152),
                Color.FromArgb(65, 204, 212, 230),
                Color.FromArgb(65, 237, 240, 247),
            })
            {
                model[rowIndex, colIndex].Interior = new BrushInfo(color1);
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (PatternStyle pattern in new PatternStyle[]
            {
                PatternStyle.Percent05,
                PatternStyle.Percent20,
                PatternStyle.Percent50,
                PatternStyle.Percent75,
                PatternStyle.DarkDownwardDiagonal,
                PatternStyle.LightDownwardDiagonal
            })
            {
                model[rowIndex, colIndex].Interior = new BrushInfo(pattern, Color.FromArgb(65, 237, 240, 247), Color.FromArgb(65, 57, 73, 122));
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (GradientStyle gradient in new GradientStyle[]
            {
                GradientStyle.BackwardDiagonal,
                GradientStyle.ForwardDiagonal,
                GradientStyle.PathEllipse,
                GradientStyle.PathRectangle,
                GradientStyle.Vertical,
                GradientStyle.Horizontal,
            })
            {
                model[rowIndex, colIndex].Interior     = new BrushInfo(gradient, Color.FromArgb(65, 57, 73, 122), Color.FromArgb(65, 237, 240, 247));
                model[rowIndex + 1, colIndex].Interior = new BrushInfo(gradient, Color.FromArgb(65, 237, 240, 247), Color.FromArgb(65, 51, 51, 102));
                colIndex++;
            }

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

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Font";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

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

            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,
            })
            {
                model[rowIndex, colIndex].Font.FontStyle = fontStyle;
                model[rowIndex, colIndex].Text           = Enum.Format(typeof(FontStyle), fontStyle, "G");
                colIndex++;
            }

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

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "TextColor";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

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

            rowIndex++;
            rowIndex++;

            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Number Formats";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (string format2 in new string[]
            {
                "0.00",
                "C",
                "0.00;(0.00)",
                "###0.##%",
                "#0.#E+00",
                "10:##,##0.#"
            })
            {
                model[rowIndex, colIndex].Format        = format2;
                model[rowIndex, colIndex].CellValue     = Math.PI;
                model[rowIndex, colIndex].CellValueType = typeof(double);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "DateTime Formats";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            foreach (string format in new string[]
            {
                "d",
                "D",
                "f",
                "dddd, dd MMMM yyyy",
                "t",
                "s"
            })
            {
                model[rowIndex, colIndex].Format        = format;
                model[rowIndex, colIndex].CellValue     = DateTime.Now;
                model[rowIndex, colIndex].CellValueType = typeof(DateTime);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Validation";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            model[rowIndex, 1].Text = "Positive numbers";
            model.RowStyles[rowIndex].ValidateValue.NumberRequired = true;
            model.RowStyles[rowIndex].ValidateValue.Minimum        = 0;
            model.RowStyles[rowIndex].ValidateValue.Maximum        = float.NaN;
            model.RowStyles[rowIndex].ValidateValue.ErrorMessage   = "Please enter a number greater than 0!";
            rowIndex++;

            model[rowIndex, 1].Text = "Validation (1-100 valid range)";
            model.RowStyles[rowIndex].ValidateValue = new GridCellValidateValueInfo(true, 1, 100, "Please enter a number between 1 and 100!");
            rowIndex++;
            rowIndex++;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Cell Types";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;

            model.TableStyle.CheckBoxOptions     = new GridCheckBoxCellInfo("True", "False", "", false);
            model[rowIndex, 1].Text              = "CheckBox";
            model[rowIndex, 3].CellType          = "CheckBox";
            model[rowIndex, 3].TriState          = false;
            model[rowIndex, 3].Text              = "True";
            model[rowIndex, 3].VerticalAlignment = GridVerticalAlignment.Middle;
            model[rowIndex, 3].Description       = "Enabled";
            model[rowIndex, 4].CellType          = "CheckBox";
            model[rowIndex, 4].Text              = "False";
            model[rowIndex, 4].Enabled           = false;
            model[rowIndex, 4].Description       = "Disabled";
            model[rowIndex, 4].VerticalAlignment = GridVerticalAlignment.Middle;
            model[rowIndex, 5].CellType          = "CheckBox";
            model[rowIndex, 5].TriState          = true;
            model[rowIndex, 5].Description       = "TriState";
            model[rowIndex, 5].VerticalAlignment = GridVerticalAlignment.Middle;
            rowIndex++;

            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text     = "DragButton";
            model[rowIndex, 3].Text     = "Drag";
            model[rowIndex, 3].CellType = "DragButton";
            rowIndex++;

            model.TableStyle.NumericUpDown = new GridNumericUpDownCellInfo(0, 25, 1, 1, true);
            model[rowIndex, 1].Text        = "NumericUpDown";
            // Wrapping, Range 0-1000
            model[rowIndex, 3].CellType      = "NumericUpDown";
            model[rowIndex, 3].NumericUpDown = new GridNumericUpDownCellInfo(0, 1000, 0, 1, true);
            // Disabled
            model[rowIndex, 4].CellType = "NumericUpDown";
            model[rowIndex, 4].Enabled  = false;
            model[rowIndex, 4].Text     = "5";
            // No wrapping, Range 1-20
            model[rowIndex, 5].CellType      = "NumericUpDown";
            model[rowIndex, 5].NumericUpDown = new GridNumericUpDownCellInfo(1, 20, 1, 1, false);
            rowIndex++;

            model[rowIndex, 1].Text        = "PushButton";
            model[rowIndex, 3].CellType    = "PushButton";
            model[rowIndex, 3].Description = "Enabled";
            model[rowIndex, 4].CellType    = "PushButton";
            model[rowIndex, 4].Enabled     = false;
            model[rowIndex, 4].Clickable   = false;
            model[rowIndex, 4].Description = "Disabled";
            rowIndex++;

            StringCollection items = new StringCollection();

            items.Add("One");
            items.Add("Two");
            items.Add("Three");
            items.Add("Four");
            items.Add("Five");
            items.Add("Six");
            items.Add("Seven");
            items.Add("Eight");
            items.Add("Nine");
            items.Add("Ten");

            model[rowIndex, 1].Text = "ComboBox (Edit)";

            model[rowIndex, 3].CellType   = "ComboBox";
            model[rowIndex, 3].ChoiceList = items;
            // Disabled
            model[rowIndex, 4].CellType   = "ComboBox";
            model[rowIndex, 4].ChoiceList = items;
            model[rowIndex, 4].Enabled    = false;
            model[rowIndex, 4].CellValue  = items[5];
            rowIndex++;

            model[rowIndex, 1].Text = "ComboBox (List)";

            model[rowIndex, 3].CellType            = "ComboBox";
            model[rowIndex, 3].ChoiceList          = items;
            model[rowIndex, 3].ExclusiveChoiceList = true;              // tell combobox to behave like CBS_DROPDOWNSTYLE
            // Disabled
            model[rowIndex, 4].CellType            = "ComboBox";
            model[rowIndex, 4].ChoiceList          = items;
            model[rowIndex, 4].Enabled             = false;
            model[rowIndex, 4].ExclusiveChoiceList = true;              // tell combobox to behave like CBS_DROPDOWNSTYLE
            model[rowIndex, 4].CellValue           = items[5];
            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text       = "GridListControl (Edit)";
            model[rowIndex, 3].CellType   = "GridListControl";
            model[rowIndex, 3].DataSource = USStates;

            // Disabled
            model[rowIndex, 4].CellType   = "GridListControl";
            model[rowIndex, 4].DataSource = USStates;
            rowIndex++;

            model[rowIndex, 1].Text = "GridListControl (List)";

            model[rowIndex, 3].CellType            = "GridListControl";
            model[rowIndex, 3].DataSource          = USStates;
            model[rowIndex, 3].ExclusiveChoiceList = true;              // tell combobox to behave like CBS_DROPDOWNSTYLE
            rowIndex++;
            rowIndex++;


            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "DropDown Cells";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            //
            model[rowIndex, 1].Text     = "Generic DropDown";
            model[rowIndex, 3].CellType = "DropDown";
            rowIndex++;

            model[rowIndex, 1].Text     = "MonthCalendar";
            model[rowIndex, 3].CellType = "MonthCalendar";
            rowIndex++;

            model[rowIndex, 1].Text     = "ColorEdit";
            model[rowIndex, 3].CellType = "ColorEdit";
            rowIndex++;

            model[rowIndex, 1].Text     = "DropDownGrid";
            model[rowIndex, 3].CellType = "DropDownGrid";
            rowIndex++;
            rowIndex++;

            colIndex = 1;

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Borders";
            model.ChangeCells(GridRangeInfo.Cell(rowIndex, 1), boldFontStyle);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (GridBorder border2 in new GridBorder[] {
                new GridBorder(GridBorderStyle.Solid, Color.FromArgb(57, 73, 122)),
                new GridBorder(GridBorderStyle.Dotted, Color.FromArgb(238, 122, 3)),
                new GridBorder(GridBorderStyle.DashDot, Color.FromArgb(57, 73, 122)),
                new GridBorder(GridBorderStyle.DashDotDot, Color.FromArgb(238, 122, 3)),
                new GridBorder(GridBorderStyle.Dashed, Color.FromArgb(57, 73, 122), GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Dotted, Color.FromArgb(238, 122, 3), GridBorderWeight.Medium),
            })
            {
                model[rowIndex, colIndex].Borders.Bottom = border2;
                model[rowIndex, colIndex].Borders.Right  = border2;
                model[rowIndex, colIndex].Text           = border2.ToString();
                colIndex++;
            }

            rowIndex++;
            colIndex = 1;
            foreach (GridBorder border in new GridBorder[] {
                new GridBorder(GridBorderStyle.Dashed, Color.FromArgb(57, 73, 122), GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Dotted, Color.FromArgb(238, 122, 3), GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.DashDot, Color.FromArgb(57, 73, 122), GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.DashDotDot, Color.FromArgb(238, 122, 3), GridBorderWeight.Medium),
                new GridBorder(GridBorderStyle.Solid, Color.FromArgb(57, 73, 122), GridBorderWeight.Thick),
                new GridBorder(GridBorderStyle.Solid, Color.FromArgb(238, 122, 3), GridBorderWeight.Medium),
            })
            {
                model[rowIndex, colIndex].Borders.Bottom = border;
                model[rowIndex, colIndex].Borders.Right  = border;
                model[rowIndex, colIndex].Text           = border.ToString();
                colIndex++;
            }

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

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Orientation";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (int orientation in new int[]
            {
                0,
                45,
                60,
                90,
                180,
                -90
            })
            {
                GridStyleInfo style1 = model[rowIndex, colIndex];
                // style1 is a direct reference to model[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++;
            }

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

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Enabled";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            foreach (bool enabled1 in new bool[]
            {
                true,
                false,
                true,
                false,
                false,
                true,
            })
            {
                model[rowIndex, colIndex].Text     = enabled1?"YES":"NO";
                model[rowIndex, colIndex].Interior = new BrushInfo((Color)(enabled1?Color.FromArgb(65, 57, 73, 122):Color.FromArgb(65, 238, 122, 3)));
                model[rowIndex, colIndex].Enabled  = enabled1;
                colIndex++;
            }

            colIndex = 1;
            rowIndex++;

            foreach (bool enabled2 in new bool[]
            {
                true,
                true,
                false,
                false,
                false,
                true,
            })
            {
                model[rowIndex, colIndex].Text     = enabled2?"YES":"NO";
                model[rowIndex, colIndex].Interior = new BrushInfo((Color)(enabled2?Color.FromArgb(65, 57, 73, 122):Color.FromArgb(65, 238, 122, 3)));
                model[rowIndex, colIndex].Enabled  = enabled2;
                colIndex++;
            }

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

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "AutoSize";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            model.RowStyles[rowIndex].AutoSize = true;
            model.RowStyles[rowIndex].Text     = "Row height will increase while you type text";
            model.RowStyles[rowIndex].Interior = new BrushInfo(Color.Beige);

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

            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text = "Read Only";
            model[rowIndex, 1].ModifyStyle(boldFontStyle, StyleModifyType.Override);
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            model.RowStyles[rowIndex].ReadOnly = true;
            model.RowStyles[rowIndex].Interior = new BrushInfo(Color.LightGray);
            model.RowStyles[rowIndex].Text     = "ReadOnly";
            rowIndex++;
            rowIndex++;


            model.Options.ExcelLikeCurrentCell        = false;
            model.Options.ExcelLikeSelectionFrame     = false;
            model.Options.ActivateCurrentCellBehavior = GridCellActivateAction.ClickOnCell;
            model.Properties.MarkColHeader            = true;
            model.Properties.MarkRowHeader            = true;

            model.RowHeights.ResizeToFit(GridRangeInfo.Cells(2, 1, rowIndex, 3), GridResizeToFitOptions.ResizeCoveredCells | GridResizeToFitOptions.NoShrinkSize);
            model.EndInit();
        }
Exemplo n.º 3
0
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            #region Style settings
            GridModel model = gridControl1.Model;
            model.Options.FloatCellsMode = GridFloatCellsMode.OnDemandCalculation;

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

            int rowIndex = 2;
            int colIndex = 1;

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

            model.Options.ControllerOptions         = GridControllerOptions.All;
            model.Options.DataObjectConsumerOptions = GridDataObjectConsumerOptions.All;

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

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

            standard.Font.Facename     = "Segoe UI";
            standard.VerticalAlignment = GridVerticalAlignment.Middle;

            #endregion

            #region Number Formats
            model.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex, 2));
            model[rowIndex, 1].Text    = "Number Formats";
            model[rowIndex, 1].Font    = boldFont;
            model.RowHeights[rowIndex] = boldfontRowHeight;
            rowIndex++;

            colIndex = 1;
            rowIndex++;
            foreach (string format in new string[]
            {
                "0.00",
                "C",
                "0.00;(0.00)",
                "###0.##%",
                "#0.#E+00",
                "10:##,##0.#"
            })
            {
                model[rowIndex - 1, colIndex].Text      = format;
                model[rowIndex, colIndex].Format        = format;
                model[rowIndex, colIndex].CellValue     = Math.PI;
                model[rowIndex, colIndex].CellValueType = typeof(double);
                colIndex++;
            }
            #endregion

            #region Date Formats

            rowIndex++;
            rowIndex++;

            colIndex = 1;

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

            colIndex = 1;
            rowIndex++;
            foreach (string format in new string[]
            {
                "d",
                "D",
                "f",
                "dddd, dd MMMM yyyy",
                "t",
                "s"
            })
            {
                model[rowIndex - 1, colIndex].Text      = format;
                model[rowIndex, colIndex].Format        = format;
                model[rowIndex, colIndex].CellValue     = DateTime.Now;
                model[rowIndex, colIndex].CellValueType = typeof(DateTime);
                colIndex++;
            }

            rowIndex++;
            rowIndex++;
            #endregion

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

            model[rowIndex, 1].Text = "Positive numbers";
            model.RowStyles[rowIndex].ValidateValue.NumberRequired = true;
            model.RowStyles[rowIndex].ValidateValue.Minimum        = 0;
            model.RowStyles[rowIndex].ValidateValue.Maximum        = float.NaN;
            model.RowStyles[rowIndex].ValidateValue.ErrorMessage   = "Please enter a number greater than 0!";
            rowIndex++;

            model[rowIndex, 1].Text = "Validation (1-100 valid range)";
            model.RowStyles[rowIndex].ValidateValue = new GridCellValidateValueInfo(true, 1, 100, "Please enter a number between 1 and 100!");
            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text = "Validation (allow strings to be entered into cells with CellValueType = typeof(double)";
            rowIndex++;
            model.RowStyles[rowIndex].CellValueType   = typeof(double);
            model.RowStyles[rowIndex].CellValue       = 1;
            model.RowStyles[rowIndex].Format          = "C";
            model.RowStyles[rowIndex].StrictValueType = false;
            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text = "Validation (do not allow strings to be entered)";
            rowIndex++;
            model.RowStyles[rowIndex].CellValueType   = typeof(double);
            model.RowStyles[rowIndex].CellValue       = 1;
            model.RowStyles[rowIndex].Format          = "C";
            model.RowStyles[rowIndex].StrictValueType = true;
            rowIndex++;
            rowIndex++;

            model[rowIndex, 1].Text = "Validation (change CellValueType when strings is entered)";
            rowIndex++;
            model.RowStyles[rowIndex].CellValueType = typeof(double);
            model.RowStyles[rowIndex].CellValue     = 1;
            model.RowStyles[rowIndex].Format        = "C";
            model.RowStyles[rowIndex].Tag           = "Custom";
            rowIndex++;
            rowIndex++;
            #endregion

            #region TableStyle
            model.RowHeights.ResizeToFit(GridRangeInfo.Rows(2, rowIndex));
            this.gridControl1.DefaultRowHeight       = 18;
            this.gridControl1.DefaultColWidth        = 70;
            this.gridControl1.DefaultGridBorderStyle = GridBorderStyle.Solid;
            this.gridControl1.Font = new System.Drawing.Font("Segoe UI", 8.5F);
            #endregion

            this.GridSettings();
        }
Exemplo n.º 4
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
        }