/// <summary> /// Customizing Grid cells /// </summary> private void initializeGrid() { #region Style declaration this.gridControl1.DefaultRowHeight = 18; GridStyleInfo headerstyle = new GridStyleInfo(); headerstyle.Font.Size = 12; headerstyle.Font.Bold = true; headerstyle.TextColor = Color.Black; headerstyle.VerticalAlignment = GridVerticalAlignment.Middle; headerstyle.HorizontalAlignment = GridHorizontalAlignment.Center; headerstyle.CellType = GridCellTypeName.Static; GridStyleInfo subheaderstyle = new GridStyleInfo(); subheaderstyle.Font.Bold = true; subheaderstyle.VerticalAlignment = GridVerticalAlignment.Middle; subheaderstyle.HorizontalAlignment = GridHorizontalAlignment.Center; subheaderstyle.CellType = GridCellTypeName.Static; GridStyleInfo valuestyle = new GridStyleInfo(); valuestyle.BackColor = SystemColors.Menu; valuestyle.TextColor = Color.Black; valuestyle.VerticalAlignment = GridVerticalAlignment.Middle; valuestyle.HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1.FloatCellsMode = GridFloatCellsMode.BeforeDisplayCalculation; int rowIndex = 1, colIndex = 2; #endregion #region Float Cells gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "FloatingCells"; rowIndex += 3; gridControl1[rowIndex, colIndex] = valuestyle; gridControl1[rowIndex, colIndex].Text = "Control Overview"; rowIndex++; gridControl1.Model.TextDataExchange.PasteTextFromBuffer( String.Concat( "Public Properties\r\n", "BackColor\tGets or sets the background color for the control. \r\n", "Controls\tGets the collection of controls contained within the control. \r\n", "Cursor\tGets or sets the cursor that is displayed when the mouse pointer is over the control. \r\n", "DefaultBackColor\tGets the default background color of the control. \r\n", "DefaultForeColor\tGets the default foreground color of the control. \r\n", "Dock\tGets or sets which edge of the parent container a control is docked to. \r\n", "Enabled\tGets or sets a value indicating whether the control can respond to user interaction. \r\n", "Font\tGets or sets the font of the text displayed by the control. \r\n", "ForeColor\tGets or sets the foreground color of the control. \r\n", ""), GridRangeInfo.Cell(rowIndex, colIndex), int.MaxValue); gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Cells(1, 1, gridControl1.RowCount, gridControl1.ColCount)); #endregion #region CoveredCell rowIndex = 16; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "Covered Cells"; rowIndex += 3; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, colIndex, rowIndex + 2, colIndex + 1)); gridControl1[rowIndex, colIndex].BackColor = Color.Orange; gridControl1[rowIndex, colIndex].Text = "Covered in rows & cols"; gridControl1[rowIndex, colIndex].TextColor = Color.Black; gridControl1[rowIndex, colIndex].Font.Bold = true; gridControl1[rowIndex, colIndex].VerticalAlignment = GridVerticalAlignment.Middle; gridControl1[rowIndex, colIndex].HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, colIndex + 3, rowIndex, colIndex + 5)); gridControl1[rowIndex, colIndex + 3].BackColor = Color.Orange; gridControl1[rowIndex, colIndex + 3].Text = "Covered in cols"; gridControl1[rowIndex, colIndex + 3].TextColor = Color.Black; gridControl1[rowIndex, colIndex + 3].Font.Bold = true; gridControl1[rowIndex, colIndex + 3].VerticalAlignment = GridVerticalAlignment.Middle; gridControl1[rowIndex, colIndex + 3].HorizontalAlignment = GridHorizontalAlignment.Center; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, colIndex + 7, rowIndex + 5, colIndex + 7)); gridControl1[rowIndex, colIndex + 7].BackColor = Color.Orange; gridControl1[rowIndex, colIndex + 7].Text = "Cov. in rows"; gridControl1[rowIndex, colIndex + 7].TextColor = Color.Black; gridControl1[rowIndex, colIndex + 7].Font.Bold = true; gridControl1[rowIndex, colIndex + 7].VerticalAlignment = GridVerticalAlignment.Middle; gridControl1[rowIndex, colIndex + 7].HorizontalAlignment = GridHorizontalAlignment.Center; #endregion #region Banner Cells rowIndex = 26; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "Banner Cells"; rowIndex += 3; GridStyleInfo style; style = gridControl1[rowIndex, colIndex]; gridControl1.BanneredRanges.Add(GridRangeInfo.FromTlhw(rowIndex, colIndex, 8, colIndex + 1)); style.BackgroundImage = GetImage(@"cloud2.png"); style.Text = "cloud2.png"; style.TextColor = Color.Red; style.BackgroundImageMode = GridBackgroundImageMode.StretchImage; style = gridControl1[rowIndex, colIndex + 5]; gridControl1.BanneredRanges.Add(GridRangeInfo.FromTlhw(rowIndex, colIndex + 5, 8, colIndex + 1)); style.Interior = new BrushInfo(GradientStyle.PathEllipse, SystemColors.Highlight, Color.White); style.Text = "GradientStyle.PathEllipse"; style.TextColor = Color.Blue; #endregion #region Custom Borders rowIndex = 39; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "Custom Borders Cells"; gridControl1.DrawCellFrameAppearance += new GridDrawCellBackgroundEventHandler(gridControl1_DrawCellFrameAppearance); gridControl1.BeginUpdate(); rowIndex += 3; rindex = rowIndex; cindex = colIndex; for (int i = rowIndex; i <= rindex + 5; i++) { for (int j = colIndex; j <= cindex + 7; j++) { GridStyleInfo newstyle = gridControl1[i, j]; newstyle.BorderMargins = new GridMarginsInfo(5, 5, 5, 5); newstyle.Borders.All = GridBorder.Empty; newstyle.CellAppearance = GridCellAppearance.Flat; } } gridControl1.EndUpdate(true); #endregion #region CustomDraw gridControl1.ActivateCurrentCellBehavior = GridCellActivateAction.DblClickOnCell; rowIndex = 49; gridControl1.CoveredRanges.Add(GridRangeInfo.Cells(rowIndex, 1, rowIndex + 1, gridControl1.ColCount)); gridControl1[rowIndex, 1] = headerstyle; gridControl1[rowIndex, 1].Text = "Custom Drawing in GridCells"; //creating the datatable for the datasource DataTable dt = new DataTable(); dt.Columns.Add("BookID"); dt.Columns.Add("BookName"); dt.Columns.Add("Author"); dt.Columns.Add("Price"); dt.Rows.Add(new object[] { "BookID", "BookName", "Author", "Price" }); dt.Rows.Add(new object[] { "1001", "Computer Networks", "Tanenbaum", "75.00" }); dt.Rows.Add(new object[] { "1002", "DBMS", "Navbathe", "85.00" }); dt.Rows.Add(new object[] { "1003", "Let us C", "Leland Beck", "50.00" }); dt.Rows.Add(new object[] { "1004", "System Software", "Hamacher", "78.00" }); dt.Rows.Add(new object[] { "1005", "Computer Organization", "Carl", "50.00" }); dt.Rows.Add(new object[] { "1006", "Test your c skills", "Ivan", "75.00" }); dt.Rows.Add(new object[] { "1007", "C#.Net", "Alexis", "50.00" }); dt.Rows.Add(new object[] { "1008", "Multimedia", "Leon", "75.00" }); dt.AcceptChanges(); rowIndex += 3; gridControl1[rowIndex, 6].Text = "Cart"; gridControl1[rowIndex, 7].Text = "BookStatus"; for (int i = rowIndex + 1; i <= 60; i++) { this.gridControl1[i, 6].CellValue = 0; } gridControl1.PopulateValues(GridRangeInfo.Cells(52, 2, 60, 5), dt); for (int k = 53; k <= 60; k++) { for (int l = 2; l <= 7; l++) { //set the background of the cell gridControl1[k, l].Interior = new BrushInfo(GradientStyle.ForwardDiagonal, Color.FromArgb(255, 187, 111), Color.White); } } for (int l = 2; l <= 7; l++) { //set the celltype as header gridControl1[52, l].CellType = GridCellTypeName.Header; } this.gridControl1.CellClick += new GridCellClickEventHandler(HandleAClick); //Handle the following events to do custom painting this.gridControl1.CellDrawn += new GridDrawCellEventHandler(gridControl1_CellDrawn); this.gridControl1.DrawCell += new GridDrawCellEventHandler(gridControl1_DrawCell); #endregion }