colorize entire row in listview

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

colorize entire row in listview

Post by sal21 »

Is possible to colorize in green the fonts of entire row in a listview?

tested with:

Code: Select all

 If ICO = 1 Then
        Me.ListView1.ListItems(X).ListSubItems(2).ForeColor = &H8000&
        End If
but i need to colorize all fonts in row

Note:
X is the value from a loop in listcount

User avatar
HansV
Administrator
Posts: 78440
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: colorize entir row in listview

Post by HansV »

You could loop through the subitems to color each of them.
Best wishes,
Hans

syswizard
4StarLounger
Posts: 584
Joined: 12 Jul 2012, 10:34

Re: colorize entire row in listview

Post by syswizard »

Hans - why are so many users enamored with the ListView control ?
Didn't you say it was effectively broken (or buggy) ?

User avatar
HansV
Administrator
Posts: 78440
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: colorize entire row in listview

Post by HansV »

It's mostly sal21 who's enamored with it. :grin:

Since it's not a native Excel (or Office) control, the ListView control may not work on all PCs, and even if it does work it may behave quirkily.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: colorize entir row in listview

Post by sal21 »

HansV wrote:You could loop through the subitems to color each of them.
ok i know this way... but difficut to set the first cell!

User avatar
HansV
Administrator
Posts: 78440
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: colorize entire row in listview

Post by HansV »

Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: colorize entire row in listview

Post by sal21 »

ERROR!!!!!!!!!!!

I need to colorize entire row in listview with red if condition exists....

Code: Select all

Sub LOOP_COLOR()

    Dim itmX As ListItem
    Dim LINEA As Long

    'INSERIRE LA CONDIZIONE PER ROWSET ROSSO
    For LINEA = 1 To Me.ListView1.ListItems.Count
        If Me.ListView1.ListItems(LINEA).SubItems(2) = "05" Then
            Dim lvSI As ListSubItem
            Dim intIndex As Integer
            For intIndex = 1 To Me.ListView1.ColumnHeaders.Count - 1
                Set lvSI = itmX.ListSubItems(intIndex)<<<<<<<<<<<<<<<<<< error 91
                lvSI.ForeColor = vbRed
            Next
        End If
    Next LINEA
    'INSERIRE LA CONDIZIONE PER ROWSET ROSSO

End Sub

User avatar
HansV
Administrator
Posts: 78440
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: colorize entire row in listview

Post by HansV »

You haven't set itmX.

Code: Select all

Sub LOOP_COLOR()

    Dim itmX As ListItem
    Dim LINEA As Long

    'INSERIRE LA CONDIZIONE PER ROWSET ROSSO
    For LINEA = 1 To Me.ListView1.ListItems.Count
         Set itmX = Me.ListView1.ListItems(LINEA)  ' ***** Added line ****
        If itmX.SubItems(2) = "05" Then
            Dim lvSI As ListSubItem
            Dim intIndex As Integer
            For intIndex = 1 To Me.ListView1.ColumnHeaders.Count - 1
                Set lvSI = itmX.ListSubItems(intIndex)
                lvSI.ForeColor = vbRed
            Next
        End If
    Next LINEA
    'INSERIRE LA CONDIZIONE PER ROWSET ROSSO
End Sub
Best wishes,
Hans