Home Forums WinForms controls Xceed Grid for WinForms How to create multiple column headers Reply To: How to create multiple column headers

User (Old forums)
Member
Post count: 23064

No, they are not real columns, it is only a way of grouping columns together under common headers.

You need to add a custom text to each cell of these headers yourself.  You need to do this in the PaintForeground.

e.g. :

protected override void PaintForeground( GridPaintEventArgs e )

{

    int width = 0;

    int lastColumn = 0;

    for( int j = 0; j < this.GridControl.Columns.Count / m_columns; j++ )

    {

        //this is where we set the text of the new grouped column

        e.Graphics.DrawString( “some grouped column”, GridControl.Font, new System.Drawing.SolidBrush( Color.Black ), new Point( e.DisplayRectangle.X + width, e.DisplayRectangle.Y ) );

        for( int i = 0; i < m_columns; i++ )

        {

            width +=

this.GridControl.Columns[ lastColumn ].Width;

            lastColumn++;

        }

        e.Graphics.DrawLine(

this.GridControl.GridLinePen, e.DisplayRectangle.X + width – 1, 0, e.DisplayRectangle.X + width – 1, this.Height );

    }

}

Imported from legacy forums. Posted by André (had 865 views)