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

Custom Column Header

In a GridControl i want to draw something different from the arrow when i sort. Is is possible (actually i would like to draw the sort order number) Thanks S. Lombardi

8 Replies

AD Administrator Syncfusion Team February 23, 2005 03:01 PM UTC

There are several ways to approach this. One is to derive your own cell type and use it for the sorted column headers. The sample, \Syncfusion\Essential Suite\\Windows\Grid.Windows\Samples\Quick Start\GridControlSort\, shows how you can control the column header or a sorted column, specifying the CellType for that column. That sample uses teh default "ColumnHeaderCell" celltype to control the look of teh cell. You would want to replace this with you own celltype. Something that might be simpler is to handle the CellDrawn event, and there you could just overdraw the sort bitmap with one of your choosing. Here is a forum thread that discusses how to overpaint the triangle in the current row header cell. You could try something similar with the sorted column header. To id the sorted column header, you can check the style.Tag for the cell is a ListSortDirection value or not.

AD Administrator Syncfusion Team February 23, 2005 03:47 PM UTC

Where is the thread ?

AD Administrator Syncfusion Team February 23, 2005 03:49 PM UTC

Also when allowing colum dragging, there is a conflict with the sorting. Because the click is handled by both event. How to overcome this problem ?

AD Administrator Syncfusion Team February 23, 2005 04:09 PM UTC

Here is the first link. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=23698 One way to handle the second question is to set the SortBehavior property to DoubleClick. If you do not want to do this, here is another is another thread with a different solution. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=9676

AD Administrator Syncfusion Team February 23, 2005 04:39 PM UTC

The example of the first trade triggers an exception with a gridcontrol...

AD Administrator Syncfusion Team February 23, 2005 05:02 PM UTC

I do not know what that means. Can you upload a sample showing the problem you are having (or send it to support@syncfusion.com and mention this thread in the subjext line)?

AD Administrator Syncfusion Team February 23, 2005 05:34 PM UTC

I found the problem. But the icon is in the middle of the cell shadowing the header name: private void _grid_CellDrawn(object sender, GridDrawCellEventArgs e) { if(e.ColIndex > 0 && e.RowIndex == 0) { Rectangle rect = GridUtil.CenterInRect(e.Bounds, this._imageList.ImageSize); GridStaticCellRenderer.DrawImage(e.Graphics, this._imageList, 0, rect); } } How do you check the tag and how do you know if we are sorting in this column ?

AD Administrator Syncfusion Team February 23, 2005 06:26 PM UTC

You get the Tag from the style object for the cell. object tag = grid[r.RowIndex, e.ColIndex].Tag; The grid actually uses OnDrawCellDisplayText to draw the sort header. Here is the code it uses to decide where to draw it. protected override void OnDrawDisplayText(Graphics g, Rectangle textRectangle, int rowIndex, int colIndex, GridStyleInfo style) { // No arrow needed when printing. object tag = style.Tag; if (Grid.PrintingMode || !(tag is ListSortDirection)) tag = null; ListSortDirection listSortDirection = ListSortDirection.Ascending; int margin = 0; if (tag != null) { listSortDirection = (ListSortDirection) tag; margin = 12; } if (Grid.IsRightToLeft()) GridUtil.OffsetLeft(ref textRectangle, margin); else textRectangle.Width -= margin; base.OnDrawDisplayText(g, textRectangle, rowIndex, colIndex, style); if (tag != null) { Rectangle rect; if (Grid.IsRightToLeft()) rect = new Rectangle(textRectangle.Left-margin, textRectangle.Y, 10, textRectangle.Height); else rect = new Rectangle(textRectangle.Right, textRectangle.Y, 10, textRectangle.Height); rect = GridUtil.CenterInRect(rect, new Size(8, 8)); Brush brush = new SolidBrush(SystemColors.ControlDark); //g.FillRectangle(brush, rect); int i2 = Math.Max(0, (rect.Height - 3) / 2); rect.Inflate(-i2, -i2); Pen pen1 = new Pen(SystemColors.WindowFrame); Pen pen2 = new Pen(SystemColors.Control); GridTriangleDirection triangleDirection = listSortDirection == ListSortDirection.Ascending ? GridTriangleDirection.Up : GridTriangleDirection.Down; GridPaintTriangle.Paint(g, rect, triangleDirection, brush, pen1, true); pen1.Dispose(); pen2.Dispose(); brush.Dispose(); } }

Live Chat Icon For mobile
Up arrow icon