Change forecolor of entire row in Listview VB6

Hello!
I have a question, I have a listview control in vb6 and am using the itemclick sub and I need to get the whole row selected by the user to turn red when clicked by the user.  I have been able to get the item to turn red but not the whole selected row.  any ideas?

Thanks!
zraptorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Public Sub ColorListviewRow(lv As ListView, RowNbr As Long, RowColor As OLE_COLOR)
'***************************************************************************
'Purpose: Color a ListView Row
'Inputs : lv - The ListView
'         RowNbr - The index of the row to be colored
'         RowColor - The color to color it
'Outputs:
'***************************************************************************
    
    Dim itmX As ListItem
    Dim lvSI As ListSubItem
    Dim intIndex As Integer
    
    On Error GoTo ErrorRoutine
    
    Set itmX = lv.ListItems(RowNbr)
    itmX.ForeColor = RowColor
    For intIndex = 1 To lv.ColumnHeaders.Count - 1
        Set lvSI = itmX.ListSubItems(intIndex)
        lvSI.ForeColor = RowColor
    Next

    lv.ListItems(RowNbr).Selected = True
    
    Set itmX = Nothing
    Set lvSI = Nothing
    
    Exit Sub

ErrorRoutine:

    MsgBox Err.Description

End Sub

Open in new window

0
zraptorAuthor Commented:
ok, the question now is I already have a item click routine, how do I build that into it?

I tried  call ColorListviewow(listview1, , vbred) but didnt work....
0
Martin LissOlder than dirtCommented:
Colorlistviewrow listview1, 5, vbRed

Should color row 5. I know the routine works because I use it in one of my apps.
0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

zraptorAuthor Commented:
I got that but, I need the row to be the row the user selected, how do I get that into the above?  O am I just stupid?  haha
0
Martin LissOlder than dirtCommented:
Okay this code should work anyplace you put it after you change lvFind to the name of your listview in the several places it's used.


    Dim itmX As ListItem
    Dim lvSI As ListSubItem
    Dim intIndex As Integer
    Dim intRow As Integer
    
    For intRow = 1 To lvFind.ListItems.Count
        If lvFind.ListItems(intRow).Selected Then
            Set itmX = lvFind.ListItems(intRow)
            itmX.ForeColor = vbRed
            For intIndex = 1 To lvFind.ColumnHeaders.Count - 1
                Set lvSI = itmX.ListSubItems(intIndex)
                lvSI.ForeColor = vbRed
            Next
        End If
    Next


    Set itmX = Nothing
    Set lvSI = Nothing

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zraptorAuthor Commented:
Awesome, Thanks for the help!!
0
Martin LissOlder than dirtCommented:
I'm glad I was able to help.
0
Biju VarkeyCommented:
Martin, Thank you for the support
I have an issue with my listview:- when  I click one row, the color of entire row changes but when I click another row first row remain same in color. Is there any way to return all other items to black and only the selected row to turn in red?. Thanks in advance
Biju Varkey
0
Martin LissOlder than dirtCommented:
Please ask a new question.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows XP

From novice to tech pro — start learning today.