Solved

Custom Column Color changes text color in ListView

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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Footer for each row on Gridview 2 41
ASP/VB email question 4 63
vb.net class 3 30
"Emulate" TAB key when press Enter Key 3 74
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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

726 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