We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Turning off column header selection border in GridControl

Hi, I have a GridControl ( in a form. I have my own ColumnHeaderCellRenderer derived from GridStaticCellRenderer and ColumnHeaderHeaderCellModel derived from GridStaticCellModel. Everything works fine except that I am getting a black rectangle around the column header when I click on the header. How can I make it not draw that border when I click on the column header? thanks, - Reddy

3 Replies

AD Administrator Syncfusion Team September 8, 2003 02:33 PM UTC

Try handling the DrawCurrentCellBorder event, and canceling it if you are on a header cell.
Private Sub GridControl1_DrawCurrentCellBorder(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridDrawCurrentCellBorderEventArgs) Handles GridControl1.DrawCurrentCellBorder
        If e.RowIndex = 0 Or e.ColIndex = 0 Then
            e.Cancel = True
        End If
    End Sub

AD Administrator Syncfusion Team September 9, 2003 07:15 PM UTC

Clay, Thank you very much for your reply. It works great. I have another problem. When I click on the column header, it is not drawing the column header as selected (with blue alpha-belnding). It draws all the rest of the rows in that column as selected. When I select multiple columns, it is drawing the rest of the columns (including headers) as selected. When I switch to another MDI window and come back, it is drawing all the selected column headers with alpha-blend selection. Any ideas? thanks, - Reddy Here is the cell renderer --------------------------------------------- public class ReportColumnHeaderCellRenderer : GridStaticCellRenderer { /// /// The default font to be used in the cell header /// public static GridFontInfo defaultFont = null; /// /// Initializes a new ReportColumnHeaderCellRenderer object for the /// given GridControlBase and GridCellModel. /// /// The GridControlBase that display this cell /// renderer /// The GridCellModelBase that holds data for /// this cell renderer that shoud be shared among views public ReportColumnHeaderCellRenderer(GridControlBase grid, GridCellModelBase cellModel) : base(grid, cellModel) { } /// /// This method is celled fro the cell renderers Draw method to draw /// the contents of the client bounds for the cell, e.g. the text for /// header cell /// /// Points to the device graphics /// Specifies the client rectangle. It /// is the cell rectangle without buttons and borders /// Specifies the row id /// Specifies the column id /// A reference to the style object of the cell protected override void OnDraw(System.Drawing.Graphics g, System.Drawing.Rectangle clientRectangle, int rowIndex, int colIndex, Syncfusion.Windows.Forms.Grid.GridStyleInfo style) { if (ReportColumnHeaderCellRenderer.defaultFont != null) { style.Font = ReportColumnHeaderCellRenderer.defaultFont; } Rectangle rc = clientRectangle; base.OnDraw(g, rc, rowIndex, colIndex, style); using(Pen blackPen = new Pen(Color.Black, 1)) { // draw the column underline if (colIndex != 1) { g.DrawLine(blackPen, rc.Left + 5, rc.Bottom-2, rc.Right - 7, rc.Bottom-2); } // draw the vert resize handle if (!Grid.PrintingMode) { int handleHeight = 4; int x = rc.Right-2; int y = (rc.Bottom - rc.Top)/2; using(Pen grayPen = new Pen(Color.LightGray, 1)) { g.DrawLine(grayPen, x, y-handleHeight, x, y+handleHeight); } } } }

AD Administrator Syncfusion Team September 9, 2003 09:51 PM UTC

Here is code that will handle this problem in the grid.CellDrawn event. Maybe you can check to see if the cell being drawn is the current cell at the end of your OnDraw override. And if it is, then draw the alpha selection color over the cell.
private void gridControl1_CellDrawn(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
	GridCurrentCell cc = this.gridControl1.CurrentCell;
	if(e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex
		&& this.gridControl1.Selections.Ranges.AnyRangeContains(GridRangeInfo.Cell(e.RowIndex, e.ColIndex))
		&& !cc.IsEditing)
		SolidBrush br = new SolidBrush(this.gridControl1.AlphaBlendSelectionColor);
		e.Graphics.FillRectangle(br, e.Bounds);

Live Chat Icon For mobile
Up arrow icon