[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Change ListView Highlight Color

Posted on 2010-09-09
3
Medium Priority
?
903 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
David L. Hansen earned 2000 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

Technology Partners: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 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