Solved

Custom Column Color changes text color in ListView

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

816 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

10 Experts available now in Live!

Get 1:1 Help Now