Solved

Change ListView Highlight Color

Posted on 2010-09-09
3
876 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Advice in Xamarin 21 78
get row value in vb.net 4 14
VB.Net/LINQ: ".Contains" condition not finding existing result in MSSQL 16 34
Winform Module - What is the ASP.Net equiv 2 19
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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