Solved

Custom Column Color changes text color in ListView

Posted on 2010-09-21
5
428 Views
Last Modified: 2012-05-10
Hi,

I am trying to have a custom header color in a listview. I have found a piece of code that does this, however it overrides the ForeColor color.

This is the code:
 Private Sub listView1_DrawColumnHeader(ByVal sender As Object, ByVal e As DrawListViewColumnHeaderEventArgs) Handles ListView1.DrawColumnHeader

        Dim strFormat As New StringFormat()
        e.Header.TextAlign = HorizontalAlignment.Center
        e.DrawBackground()
        e.Graphics.FillRectangle(Brushes.Black, e.Bounds)
        
        Dim headerFont As New Font("Arial", 8, FontStyle.Bold)
        e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.White, e.Bounds, strFormat)
    End Sub

Open in new window


Is there anywhere I can set the forecolor inside that function for the entire listview? Or is this code pretty crap?

Thanks
0
Comment
Question by:DanielBlackmore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 500 total points
ID: 33724735
0
 

Author Comment

by:DanielBlackmore
ID: 33725067
I have looked at this already, IT doesnt seem to work properly. I have tried modifying it but its just not working. I am trying to have a black background on the form, black table and black headers with white text.

That code wont let me change the column text color, and it also puts in place a white bar seperating the columns
0
 
LVL 33

Expert Comment

by:jppinto
ID: 33726185
Take a look at this example from Code Project:

http://www.codeproject.com/KB/list/customheader.aspx

jppinto
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33732537
"That code wont let me change the column text color, and it also puts in place a white bar seperating the columns"
You have to delete your previous Listview and drag the new one from toolbox...
after you drag the custom control into your from try check the listview properties OwnerDraw=True
Also Form The Class You might change even the fore color.....
0
 

Author Closing Comment

by:DanielBlackmore
ID: 33769984
Thanks alot!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question