Color in Listview Control? 
Author Message
 Color in Listview Control?

Hi,

Does anyone out there know how to make the forground text in a listview
control different colors?  I don't mean all of the text though... just
specific pieces of data.

For example... if one of my columns contains positive and negative numbers
I'd like to be able to make the negative numbers appear in red.

Any help would be greatly appreciated.

Alex



Sun, 27 Jan 2002 03:00:00 GMT  
 Color in Listview Control?

11 Aug 1999 23:36:35 -0700 bearing the following fruit:

Quote:
>Hi,

>Does anyone out there know how to make the forground text in a listview
>control different colors?  I don't mean all of the text though... just
>specific pieces of data.

>For example... if one of my columns contains positive and negative numbers
>I'd like to be able to make the negative numbers appear in red.

Assuming that you are in report mode,

listview1.ListSubItems(1).ForeColor = vbred

NB:  Use ListSubitems instead of subitems when generating this report.

Drac



Mon, 28 Jan 2002 03:00:00 GMT  
 Color in Listview Control?
Hi,

Thanks for the tip... but that makes the whole column red.  What I really
wanted was the ability to make the negative numbers in the column red and
leave the positive numbers black.

Is this possible?

Alex


Quote:

> 11 Aug 1999 23:36:35 -0700 bearing the following fruit:

> >Hi,

> >Does anyone out there know how to make the forground text in a listview
> >control different colors?  I don't mean all of the text though... just
> >specific pieces of data.

> >For example... if one of my columns contains positive and negative
numbers
> >I'd like to be able to make the negative numbers appear in red.

> Assuming that you are in report mode,

> listview1.ListSubItems(1).ForeColor = vbred

> NB:  Use ListSubitems instead of subitems when generating this report.

> Drac



Mon, 28 Jan 2002 03:00:00 GMT  
 Color in Listview Control?
Try it again .. listview, empty, three columns ...

Option Explicit

Private Sub Command1_Click()

   Dim itmx As ListItem
   ListView1.ListItems.Clear

   With ListView1
     Set itmx = .ListItems.Add(, , "New Line 1")
     itmx.SubItems(1) = "Sub 1"
     itmx.SubItems(2) = "Sub 1"

     Set itmx = .ListItems.Add(, , "New Line 2")
     itmx.SubItems(1) = "Sub 2"
     itmx.SubItems(2) = "Sub 2"

    'set during load
     itmx.ListSubItems(1).ForeColor = vbRed

     Set itmx = .ListItems.Add(, , "New Line 3")
     itmx.SubItems(1) = "Sub 3"
     itmx.SubItems(2) = "Sub 3"

     itmx.Selected = True
     itmx.EnsureVisible
   End With

End Sub

Private Sub Command2_Click()

   Dim itmx As ListItem
   ListView1.ListItems.Clear

   With ListView1
     Set itmx = .ListItems.Add(, , "New Line 1")
     itmx.SubItems(1) = "Sub 1"
     itmx.SubItems(2) = "Sub 1"

     Set itmx = .ListItems.Add(, , "New Line 2")
     itmx.SubItems(1) = "Sub 2"
     itmx.SubItems(2) = "Sub 2"

     Set itmx = .ListItems.Add(, , "New Line 3")
     itmx.SubItems(1) = "Sub 3"
     itmx.SubItems(2) = "Sub 3"

   End With

   'set after the fact.
   ListView1.ListItems(3).ListSubItems(2).ForeColor = vbRed

End Sub

--

Randy Birch, MVP Visual Basic

http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please correspond only using the newsgroups so all can benefit.


| Hi,
|
| Thanks for the tip... but that makes the whole column red.  What I really
| wanted was the ability to make the negative numbers in the column red and
| leave the positive numbers black.
|
| Is this possible?
|
| Alex
|


| > 11 Aug 1999 23:36:35 -0700 bearing the following fruit:
| >
| > >Hi,
| > >
| > >Does anyone out there know how to make the forground text in a listview
| > >control different colors?  I don't mean all of the text though... just
| > >specific pieces of data.
| > >
| > >For example... if one of my columns contains positive and negative
| numbers
| > >I'd like to be able to make the negative numbers appear in red.
| > >
| >
| > Assuming that you are in report mode,
| >
| > listview1.ListSubItems(1).ForeColor = vbred
| >
| > NB:  Use ListSubitems instead of subitems when generating this report.
| >
| > Drac
|
|



Mon, 28 Jan 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Colors in ListView control

2. Back Color in ListView control ?

3. Background color of Listview control

4. Background color in Listview control

5. ListView selection color (NOT Background color)

6. ListView Control ... changing background color of individual rows

7. Change colors in a listview control

8. Req: list or listview control with individually colored line items

9. Listview control colors

10. Trouble Coloring A Row in a Listview Control

11. ListView Control that allows colored rows??

12. Listview control setting text color.

 

 
Powered by phpBB® Forum Software