Click here to Skip to main content
15,063,085 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi, I want to change selected item color in listview, when using:

listview1.selecteditem(0).forecolor = color.red

it works but when i hover the mouse on it and select it again it turns to black ( the standard color of listview )

any help please?
Posted
Updated 27-Jun-16 0:28am
Comments
dimpledevani 18-Jul-12 1:08am
   
write your code on event when you select the item from list box
Leecherman 18-Jul-12 5:13am
   
thanks for your reply.
tried that and it's worked, but didn't do what i want, i don't want all the selected items to be in red color, i want the species items to be in red when selected. so i tried also that on ItemMouseHover

If e.Item.ForeColor = Color.Red Then
ListView1.ForeColor = Color.Red
ElseIf e.Item.ForeColor = Color.Black Then
ListView1.ForeColor = Color.Black
End If

but the color goes when select or hover into another items that it's forecolor is black
dimpledevani 18-Jul-12 5:44am
   
I am sorry if i am wrong but what i understood now is that you want only one item's color to be changed instead of every item you select, so i guess every time when you select an item before changing its color , loop and search if any other item's color has changed, if yes then chage it to default color and then give color to your newly selected item.
Leecherman 18-Jul-12 6:32am
   
thanks for your reply, the problem that if there is more than one item that it's forecolor is red, if I loop it will return default color, and also if i select the item which forecolor is red all the selected items will be in red same too for items with default color!
So i guess it will be not possible?

Use picture box to draw behind the lvw picture property
   
write condition if selected = true then color.red in selectedindexchnage event
   
Comments
Leecherman 18-Jul-12 5:14am
   
thanks for your reply.
tried that and it's worked, but didn't do what i want, i don't want all the selected items to be in red color, i want the species items to be in red when selected. so i tried also that on ItemMouseHover

If e.Item.ForeColor = Color.Red Then
ListView1.ForeColor = Color.Red
ElseIf e.Item.ForeColor = Color.Black Then
ListView1.ForeColor = Color.Black
End If

but the color goes when select or hover into another items that it's forecolor is black

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900