Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: How to set ListView ForeColor?


Message #1 by "Andrew Huang" <imcityhunter@o...> on Mon, 27 Aug 2001 13:56:31 -0700
Hi Andrew

I have done this exact same thing.
Not sure if it is the best solution in the world but
as you read in the recordset data check the field that
contains the date, then for each column in your ListView
that represents a field in your recordset changes its forecolor
property to vbRed. 
There is no explicit need to set the forecolor to black as it is the
default.

here is a sample of the code I used............hope it helps
it uses the same principal as you are except that it is
checking for records not updated within the last 7 days


Nigel

    'create a list view list object
    Dim lvwListItem As ListItem
    Dim dtePCDateMinus_7 As Date
    dtePCDateMinus_7 = DateValue(Date - 7)
    Dim x as Integer
    x = 1

    While Not rsLoadData.EOF
         Set lvwListItem = lvwOverview.ListItems.Add(x, ,
rsLoadData.Fields("Name"))
         lvwListItem.SubItems(1) = "" & rsLoadData.Fields("CaseType")
         lvwListItem.SubItems(2) = "" & rsLoadData.Fields("Description")
         lvwListItem.SubItems(3) = "" & rsLoadData.Fields("ClientCode")
         lvwListItem.SubItems(4) = "" & rsLoadData.Fields("StartDate")
         lvwListItem.SubItems(5) = "" & rsLoadData.Fields("LastAmended")
         lvwListItem.SubItems(6) = "" & rsLoadData.Fields("TimeSpent")
         lvwListItem.SubItems(7) = "" &
rsLoadData.Fields("CaseStatusDescription")
         lvwListItem.SubItems(8) = "" & rsLoadData.Fields("RecordID")
         lvwListItem.SubItems(9) = "" & rsLoadData.Fields("Owner")
         lvwListItem.SubItems(10) = "" &
rsLoadData.Fields("SecondaryOwner1")
         lvwListItem.SubItems(11) = "" &
rsLoadData.Fields("SecondaryOwner2")
         lvwListItem.SubItems(12) = "" & rsLoadData.Fields("TimeSequence")
         dteTestDate = DateValue(rsLoadData.Fields("LastAmended"))
         'if LastAmended is less than the
         'current PCDate (  -7 ) days then flag it
         If dteTestDate < dtePCDateMinus_7 Then
            With lvwOverview.ListItems.Item(x)
               .ForeColor = vbRed
               .ListSubItems(1).ForeColor = vbRed
               .ListSubItems(2).ForeColor = vbRed
               .ListSubItems(3).ForeColor = vbRed
               .ListSubItems(4).ForeColor = vbRed
               .ListSubItems(5).ForeColor = vbRed
               .ListSubItems(6).ForeColor = vbRed
               .ListSubItems(7).ForeColor = vbRed
               .ListSubItems(8).ForeColor = vbRed
               .ListSubItems(9).ForeColor = vbRed
               .ListSubItems(10).ForeColor = vbRed
               .ListSubItems(11).ForeColor = vbRed
               .ListSubItems(12).ForeColor = vbRed
            End With
         End If
         'if x mod 10 remainder is = 0 then
         'yield to other processes causes the list view to be repainted
         If x Mod 10 = 0 Then
            DoEvents
         End If
         
        rsLoadData.MoveNext
        x = x + 1
        'clear the test date
        dteTestDate = "00:00:00"
    Wend
    'looping done now
    'clear up
    If Not rsLoadData Is Nothing Then
      If rsLoadData.State Then
         rsLoadData.Close
      End If
      Set rsLoadData = Nothing
    End If
    Set lvwListItem = Nothing

> -----Original Message-----
> From:	Andrew Huang [SMTP:imcityhunter@o...]
> Sent:	Monday, August 27, 2001 9:57 PM
> To:	professional vb
> Subject:	[pro_vb] How to set ListView ForeColor?
> 
> I have a data calling from database need to put onto the ListView. Before
> I put them on, I need to compare the Date field. 
> DO
> If Date < "01/01/2001" then
>    the text of that record need to be Red on the ListView
> Else
>   Black
> End If
> Loop
> 
> Please help me thanks.
> -- 
> Andrew Huang

  Return to Index