For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > July 2004 > SubItems Forecolor









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author SubItems Forecolor
Joe

2004-07-28, 3:55 pm

Is it possible to change the ForeColor of SubItems in a ListView?

I would like to change the ForeColor of a SubItem in a ListView's ListItem from black to red if the value is "Not available." In the code below I get an "Invalid qualifier" on the line .SubItems(5).ForeColor = vbRed. I suspect that this is because .SubI
tems is actually an array of values.

Here's the code:

Set oLI = lvResults.ListItems.Add(, , tName)
With oLI
.SubItems(1) = rs.Fields("StudyID").Value
.SubItems(2) = rs.Fields("StudyDate").Value
.SubItems(3) = rs.Fields("Volume").Value
.SubItems(4) = rs.Fields("VolumeLocation").Value
.SubItems(5) = retrieveJukeBox(rs.Fields("Volume").Value)
If StrComp(.SubItems(5), "not found", vbTextCompare) = 0 Then
.SubItems(5).ForeColor = vbRed
End If
End With
Set oLI = Nothing

TIA,
--
Joe

VBA Automation/VB/C++/Web and DB development
Steven Burn

2004-07-28, 3:55 pm

In my experience, you can't do it on a column basis, only on a per row
basis... (I could be wrong here)

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!


"Joe" <Joe@discussions.microsoft.com> wrote in message
news:B16C4EB0-1F4C-49CA-8F46-4B8C62BE0F53@microsoft.com...
> Is it possible to change the ForeColor of SubItems in a ListView?
>
> I would like to change the ForeColor of a SubItem in a ListView's ListItem

from black to red if the value is "Not available." In the code below I get
an "Invalid qualifier" on the line .SubItems(5).ForeColor = vbRed. I
suspect that this is because .SubItems is actually an array of values.
>
> Here's the code:
>
> Set oLI = lvResults.ListItems.Add(, , tName)
> With oLI
> .SubItems(1) = rs.Fields("StudyID").Value
> .SubItems(2) = rs.Fields("StudyDate").Value
> .SubItems(3) = rs.Fields("Volume").Value
> .SubItems(4) = rs.Fields("VolumeLocation").Value
> .SubItems(5) = retrieveJukeBox(rs.Fields("Volume").Value)
> If StrComp(.SubItems(5), "not found", vbTextCompare) = 0

Then
> .SubItems(5).ForeColor = vbRed
> End If
> End With
> Set oLI = Nothing
>
> TIA,
> --
> Joe
>
> VBA Automation/VB/C++/Web and DB development



Ken Halter

2004-07-28, 3:55 pm

Joe wrote:
> Is it possible to change the ForeColor of SubItems in a ListView?
>
> I would like to change the ForeColor of a SubItem in a ListView's ListItem from black to red if the value is "Not available." In the code below I get an "Invalid qualifier" on the line .SubItems(5).ForeColor = vbRed. I suspect that this is because .Su

bItems is actually an array of values.
>
> Here's the code:
>
> Set oLI = lvResults.ListItems.Add(, , tName)
> With oLI
> .SubItems(1) = rs.Fields("StudyID").Value
> .SubItems(2) = rs.Fields("StudyDate").Value
> .SubItems(3) = rs.Fields("Volume").Value
> .SubItems(4) = rs.Fields("VolumeLocation").Value
> .SubItems(5) = retrieveJukeBox(rs.Fields("Volume").Value)
> If StrComp(.SubItems(5), "not found", vbTextCompare) = 0 Then
> .SubItems(5).ForeColor = vbRed
> End If
> End With
> Set oLI = Nothing
>
> TIA,


Are you using the Common Controls 6 version of the listview? If so,
ListSubItems Forecolor is directly available.

'==========
Private Sub Form_Load()
Dim i As Integer
With ListView1
.View = lvwReport
.ColumnHeaders.Add , , "Item"
.ColumnHeaders.Add , , "SubItem"
For i = 1 To 10
With .ListItems.Add
.Text = "Item " & i
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
With .ListSubItems.Add
.Text = "SubItem " & i
.ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End With
End With
Next
End With
End Sub
'==========

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Joe

2004-07-28, 3:55 pm

Steven ,

Could I highlight the entire row in red?

Joe
--
Joe

VBA Automation/VB/C++/Web and DB development


"Steven Burn" wrote:

> In my experience, you can't do it on a column basis, only on a per row
> basis... (I could be wrong here)
>
> --
>
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
>
> "Joe" <Joe@discussions.microsoft.com> wrote in message
> news:B16C4EB0-1F4C-49CA-8F46-4B8C62BE0F53@microsoft.com...
> from black to red if the value is "Not available." In the code below I get
> an "Invalid qualifier" on the line .SubItems(5).ForeColor = vbRed. I
> suspect that this is because .SubItems is actually an array of values.
> Then
>
>
>

Joe

2004-07-28, 3:55 pm

Ken,

Thank you. What is the difference between ListSubItems and SubItems? One is a colection and the other an array?

--
Joe

VBA Automation/VB/C++/Web and DB development


"Ken Halter" wrote:

> Joe wrote:
SubItems is actually an array of values.[color=darkred]
>
> Are you using the Common Controls 6 version of the listview? If so,
> ListSubItems Forecolor is directly available.
>
> '==========
> Private Sub Form_Load()
> Dim i As Integer
> With ListView1
> .View = lvwReport
> .ColumnHeaders.Add , , "Item"
> .ColumnHeaders.Add , , "SubItem"
> For i = 1 To 10
> With .ListItems.Add
> .Text = "Item " & i
> .ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
> With .ListSubItems.Add
> .Text = "SubItem " & i
> .ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255)
> End With
> End With
> Next
> End With
> End Sub
> '==========
>
> --
> Ken Halter - MS-MVP-VB - http://www.vbsight.com
> Please keep all discussions in the groups..
>

Jeff Johnson [MVP: VB]

2004-07-28, 3:55 pm


"Joe" <Joe@discussions.microsoft.com> wrote in message
news:01806664-42C1-4B80-AE90-ECF8C3790B7F@microsoft.com...

> Thank you. What is the difference between ListSubItems and SubItems?
> One is a colection and the other an array?


Yes. Also, ListSubItems was introduced in the VB6 version of the ListView
control, whereas SubItems was around in the previous version.


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com