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.
Unfortunately, activation email could not send to your email. Please try again.

Turning off column header selection border in GridControl

Thread ID:

Created:

Updated:

Platform:

Replies:

6965 Sep 8,2003 08:34 AM Sep 9,2003 05:51 PM Windows Forms 3
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On September 8, 2003 08:34 AM

Hi, I have a GridControl (1.6.1.5) 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

Administrator [Syncfusion]
Replied On September 8, 2003 10:33 AM

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

Administrator [Syncfusion]
Replied On September 9, 2003 03:15 PM

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); } } } }

Administrator [Syncfusion]
Replied On September 9, 2003 05:51 PM

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);
		br.Dispose();
	}
}

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;