views:

136

answers:

2

Hello,

I have a DataGridView where I would like drawing custom glyph (let's suppose a triangle) on the column header when the user click on it.

I have the property EnableHeadersVisualStyles set to False.

Do you have any example or suggestions how to reach the desired result? Do I need to inherit from DataGridView, or DataGridViewColumn?

Thank you in advance, Marco

A: 

Hi, you need to do a few thing first attach handler to event GridView_CellPainting the inside the event handler do like this

void GridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
                e.PaintBackground( e.ClipBounds, true );
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString( e.FormattedValue.ToString() this.ColumnHeadersDefaultCellStyle.Font, new SolidBrush( this.ColumnHeadersDefaultCellStyle.ForeColor ),e.CellBounds, sf );

                             //
                             //Place code to draw your custom gliph
                             //
                e.Handled = true;
            }
        }

the row "sf.Alignment = StringAlignment.Near;" set text to be painted left alignemet if you need it otherwise change

IordanTanev