Solved

Change ListView Highlight Color

Posted on 2010-09-09
3
866 Views
Last Modified: 2012-05-10
I would like to be able to control the highlight color of each listview item individually depending on what their individual backcolors are. I found a way to change all of them on the form but that is not what I want. Basically, if the backcolor is a light red, I want the highlight color to be a dark red. Is this possible? Thanks.
0
Comment
Question by:rbichon
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 500 total points
ID: 33642358
Try this:

Private Sub listBox1_DrawItem(sender As Object, e As DrawItemEventArgs)

	Dim index As Integer = e.Index

	Dim g As Graphics = e.Graphics

	For Each selectedIndex As Integer In Me.listBox1.SelectedIndices

		If index = selectedIndex Then

			' Draw the new background color

			e.DrawBackground()

			g.FillRectangle(New SolidBrush(Color.Red), e.Bounds)

		End If

	Next



	' Get the item details

	Dim font As Font = listBox1.Font

	Dim colour As Color = listBox1.ForeColor

	Dim text As String = listBox1.Items(index).ToString()



	' Print the text

	g.DrawString(text, font, New SolidBrush(Color.Black), CSng(e.Bounds.X), CSng(e.Bounds.Y))

	e.DrawFocusRectangle()



End Sub



Private Sub listBox1_SelectedIndexChanged(sender As Object, e As EventArgs)

	listBox1.Invalidate()

End Sub

Open in new window

0
 
LVL 1

Author Comment

by:rbichon
ID: 33647194
I had to modify some of the code to fit my needs, but this was exactly what I was looking for. Thanks!
0
 
LVL 15

Expert Comment

by:David L. Hansen
ID: 33662066
Glad to help. :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

22 Experts available now in Live!

Get 1:1 Help Now