/// <summary> /// Setting Grid control Properties /// </summary> private void GridSettings() { this.gridControl1.ControllerOptions = GridControllerOptions.All & (~GridControllerOptions.OleDataSource); gridControl1.CommandStack.Enabled = false; this.excelMarker = new ExcelMarkerMouseController(gridControl1); gridControl1.MouseControllerDispatcher.Add(excelMarker); this.SuspendLayout(); GridBorder thickBorder = new GridBorder(GridBorderStyle.Solid, Color.Gray, GridBorderWeight.Medium); int rowIndex = rowBase + 1; int colIndex = colBase + 1; gridControl1.TableStyle.CheckBoxOptions = new GridCheckBoxCellInfo("True", "False", "", false); gridControl1[rowIndex, colIndex].CellType = "CheckBox"; gridControl1[rowIndex, colIndex].TriState = false; gridControl1[rowIndex, colIndex].Text = "True"; gridControl1[rowIndex, colIndex].VerticalAlignment = GridVerticalAlignment.Middle; gridControl1[rowIndex, colIndex].Description = " ExcelLikeCurrentCell"; rowIndex++; gridControl1[rowIndex, colIndex].CellType = "CheckBox"; gridControl1[rowIndex, colIndex].TriState = false; gridControl1[rowIndex, colIndex].Text = "True"; gridControl1[rowIndex, colIndex].VerticalAlignment = GridVerticalAlignment.Middle; gridControl1[rowIndex, colIndex].Description = " ExcelLikeSelectionFrame"; rowIndex++; gridControl1[rowIndex, colIndex].CellType = "CheckBox"; gridControl1[rowIndex, colIndex].TriState = false; gridControl1[rowIndex, colIndex].Text = "True"; gridControl1[rowIndex, colIndex].VerticalAlignment = GridVerticalAlignment.Middle; gridControl1[rowIndex, colIndex].Description = " ExcelMarker"; rowIndex++; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Top = thickBorder; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; gridControl1[rowIndex, colIndex].Text = "Selection Color"; gridControl1[rowIndex, colIndex].HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1[rowIndex, colIndex].VerticalAlignment = GridVerticalAlignment.Bottom; gridControl1[rowIndex, colIndex].Font.Size = 8; gridControl1[rowIndex, colIndex].TextColor = Color.Gray; gridControl1[rowIndex, colIndex].Enabled = false; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; gridControl1[rowIndex, colIndex].CellValue = Color.FromName("Highlight");//Color.FromArgb( 255, 187, 111 ); gridControl1[rowIndex, colIndex].CellType = "ColorEdit"; gridControl1[rowIndex, colIndex].TextColor = Color.White; gridControl1[rowIndex, colIndex].CellValueType = typeof(Color); gridControl1[rowIndex, colIndex].HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1[rowIndex, colIndex].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(163)))), ((int)(((byte)(0))))); gridControl1[rowIndex, colIndex].Font.Size = 8; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; gridControl1[rowIndex, colIndex].Text = "Alpha Blend Value (0-255)"; gridControl1[rowIndex, colIndex].HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1[rowIndex, colIndex].VerticalAlignment = GridVerticalAlignment.Bottom; gridControl1[rowIndex, colIndex].Font.Size = 8; gridControl1[rowIndex, colIndex].TextColor = Color.Gray; gridControl1[rowIndex, colIndex].Enabled = false; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; gridControl1[rowIndex, colIndex].CellType = "NumericUpDown"; gridControl1[rowIndex, colIndex].CellValue = alphaBlendValue; gridControl1[rowIndex, colIndex].CellValueType = typeof(int); gridControl1[rowIndex, colIndex].NumericUpDown = new GridNumericUpDownCellInfo(0, 255, 0, 1, true); gridControl1[rowIndex, colIndex].HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1[rowIndex, colIndex].Font.Size = 8; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; rowIndex++; gridControl1[rowIndex, colIndex].Borders.Bottom = thickBorder; gridControl1[rowIndex, colIndex].Borders.Left = thickBorder; gridControl1[rowIndex, colIndex].Borders.Right = thickBorder; gridControl1[rowIndex, colIndex].CellType = "PushButton"; gridControl1[rowIndex, colIndex].Description = "Apply"; gridControl1[rowIndex, colIndex].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(163)))), ((int)(((byte)(0))))); gridControl1.Model.RowHeights[rowIndex] = 25; gridControl1.Rows.DefaultSize += 1; gridControl1.DefaultColWidth = 70; gridControl1.ColWidths.SetSize(colIndex, 230); //add a custom cell control that draws a mitmap gridControl1.CellModels.Add("ImageCell", new ImageCellModel(gridControl1.Model)); //read a bitmap from resources //strm = this.GetType().Assembly.GetManifestResourceStream("ExcelMarker.grid.gif"); Bitmap bm = GetImage(@"Common\Images\Grid\SelectionMarker\grid.gif");// new Bitmap(strm); //set up covered cell to show the bitmap gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(1, 2, 5, 9)); gridControl1[1, 2].Tag = bm; //Tag used to hold the bitmap gridControl1[1, 2].CellType = "ImageCell"; //set some grid properties gridControl1.FloatCellsMode = GridFloatCellsMode.BeforeDisplayCalculation; gridControl1.AlphaBlendSelectionColor = Color.FromArgb(alphaBlendValue, Color.FromName("Highlight")); gridControl1.BorderStyle = BorderStyle.None; this.gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(7, 3, 10, 6)); this.gridControl1[7, 3].Borders.All = new GridBorder(GridBorderStyle.Solid, Color.Orange, GridBorderWeight.Thick); this.gridControl1[7, 3].Text = "Make some selections and then change the Excel-Like properties and selection color properties listed to the left."; this.gridControl1[7, 3].Font.Size = 9; this.gridControl1[7, 3].Font.Bold = false; this.gridControl1[7, 3].Font.Facename = "Helvetica"; this.gridControl1[7, 3].TextColor = Color.Orange; this.gridControl1[7, 3].Enabled = false; this.gridControl1[7, 3].VerticalAlignment = GridVerticalAlignment.Middle; this.gridControl1[7, 3].HorizontalAlignment = GridHorizontalAlignment.Left; //set default row height this.gridControl1.DefaultRowHeight = 22; }
//handle resetting selections after mouseclick in column 1 private void gridControl1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { int rowIndex, colIndex; gridControl1.PointToRowCol(new Point(e.X, e.Y), out rowIndex, out colIndex); if (rowIndex != mouseDownRow || colIndex != mouseDownCol) { //save the old selections so we can reset them later oldSelections = new Queue(); foreach (GridRangeInfo r in gridControl1.Selections.Ranges) { oldSelections.Enqueue(r); } } if (rowIndex == mouseDownRow && colIndex == mouseDownCol && (gridControl1[rowIndex, colIndex].CellType == "CheckBox" || gridControl1[rowIndex, colIndex].CellType == "PushButton")) { gridControl1.BeginUpdate(); switch (rowIndex - rowBase) { case 1: //ExcelCurrentCell gridControl1.ExcelLikeCurrentCell = (gridControl1[rowBase + 1, colBase + 1].Text == "True"); break; case 2: //ExcelSelectionFrame gridControl1.ExcelLikeSelectionFrame = (gridControl1[rowBase + 2, colBase + 1].Text == "True"); break; case 3: //ExcelMarker if (gridControl1[rowBase + 3, colBase + 1].Text == "True" && excelMarker == null) { this.excelMarker = new ExcelMarkerMouseController(gridControl1); gridControl1.MouseControllerDispatcher.Add(excelMarker); } else if (gridControl1[rowBase + 3, colBase + 1].Text == "False" && excelMarker != null) { gridControl1.MouseControllerDispatcher.Remove(excelMarker); excelMarker = null; } break; case 11: //apply object o = gridControl1[rowBase + 9, colBase + 1].CellValue; if (o is string) { alphaBlendValue = int.Parse((string)o); } else if (o is int) { alphaBlendValue = (int)o; } if (alphaBlendValue < 0) { MessageBox.Show("Enter the value greater than 0"); } else { o = gridControl1[rowBase + 6, colBase + 1].CellValue; if (o is string) { gridControl1.AlphaBlendSelectionColor = Color.FromArgb(alphaBlendValue, (Color)TypeDescriptor.GetConverter(typeof(Color)).ConvertFromString((string)o)); } else if (o is Color) { gridControl1.AlphaBlendSelectionColor = Color.FromArgb(alphaBlendValue, (Color)o); } } break; } //save the selections for later use if needed foreach (GridRangeInfo r in gridControl1.Selections.Ranges) { oldSelections.Enqueue(r); } gridControl1.EndUpdate(); } mouseDownRow = -1; mouseDownCol = -1; }