• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3543
  • Last Modified:

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!
0
zraptor
Asked:
zraptor
  • 5
  • 3
1 Solution
 
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now