Link to home
Start Free TrialLog in
Avatar of MikeWalters
MikeWalters

asked on

background color for a listveiw

I need to change the background color for each line of a listveiw. So if my value is blue I need that line to be blue, if it is red I need that line to be red. Please let me know what you can think of. Thanks all
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Try use ListView's BackColor Property?

Example:

Private Sub Command1_Click()
    ListView1.BackColor = vbRed
End Sub

Private Sub Command2_Click()
    ListView1.BackColor = vbBlue
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeWalters
MikeWalters

ASKER

ARK,
I am getting a error on NT when I closs the app??
Thanks for points, glad I could help you. As for error - this sample use subclassing, so you should close it from app (using [x] button on form) rather then from IDE. When compiled, this error won't occure.

Regards
Ark
Hello ! At first i would like to tell you that i have made the same question before and i will give you 70 points
if you successfully answer my question.

I tried your source code and it works ! But i tried it within my program and it crashes (kernel32.dll) . I do not
run the functions directly from form_load but after pressing a command button and after adding items to the listview.

Can you help?
Thanks!
Hello alexr123.
If you add items to listview, you have to unsubclass form first:
Call SetWindowLong(hwnd, GWL_WNDPROC, g_addProcOld)
'Now add your items:
With ListView1.ListItems.Add(,,"Blah blah")
     .Tag = CStr(QBColor(4)) 'vbRed
End With
g_MaxItems = ListView1.ListItems.Count - 1
'and subclass it again
g_addProcOld = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)

Regards
Ark
Ok thanks it worked go here and write something so that i can give you the points.

https://www.experts-exchange.com/questions/20368667/Setting-the-background-color-for-a-specific-row-in-Listview.html

Hi

I copied and pasted your code but it is closing the application.I am not able to get it will you please sort it for me please

Waiting for your Answer ASAP

Regards
Sree(SreedhaR)

Hi, don't wait for ark's response in the inmediate future. It appears like Ark has left the planet.