Link to home
Start Free TrialLog in
Avatar of greep
greep

asked on

c# Change Listview Column Header text colour.

Hi, I am trying to control the colour of selected List View Column headers at run time.

(I want to indicate to the user if one or more columns have been filtered)

I can see how to change the background. using the DrawColumnHeader event.

e.g.

 private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            if (colclick == e.ColumnIndex )
            {e.Graphics.FillRectangle(Brushes.Gainsboro, e.Bounds);
                e.DrawText();}
            else
            {e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
                e.DrawText();}
        }

But, how at the same time can I set a column header's text colour?


Thanks
Avatar of starlite551
starlite551
Flag of India image

Try it this way heres the code :
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            if (colclick == e.ColumnIndex)
            {
                e.Graphics.FillRectangle(Brushes.Gainsboro, e.Bounds);
                e.DrawText();
                e.ForeColor = Color.Blue;
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
                e.DrawText();
                e.ForeColor = Color.Red;
            }
        }

Open in new window

Change the ForeColor property to some Color..
Using ForeColor Property you can easily change the Text Color of the Column Header
Avatar of greep
greep

ASKER

Thanks, but no.    e.ForeColor = Color.Blue;     does not work

I get build errors.

Property or indexer 'System.Windows.Forms.DrawListViewColumnHeaderEventArgs.ForeColor' cannot be assigned to -- it is read only      

Is there any way to set this colour at runtime?
ASKER CERTIFIED SOLUTION
Avatar of Chuck Yetter
Chuck Yetter
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial