Solved

Custom Column Color changes text color in ListView

Posted on 2010-09-21
5
422 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
  • 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now