List View Colours

M

Mr. B

I've not programmed for a while in VB 2003... but I've decided to modlfiy a
Project I have.

Seems simple enough... I've a List Box... I fill it with about 30 lines of
data (3-4 columns).

What I want to do is to be able to List the ROWS of data either a RED or GREEN
colour depending upon an IF statement.

So... IF X =< myVariable then Row would be GREEN ELSE Row would be RED.

Orignally (before I tried to change the Colour) I had:

'Display All Results

LvItem = New ListViewItem
LvItem.Text = reqWire
LvItem.SubItems.Add(AcVolts)
LvItem.SubItems.Add(AcVoltLoss)
lvResults.Items.Add(LvItem)


Now I've (I get a colour... but all rows are the same):

'Display All Results

Dim lvs As New ListViewItem.ListViewSubItem
Dim LItem As ListViewItem
Dim nwClrA, nwClrB As Color
nwClrA = Color.PaleGreen ' Equal to or Less Than
nwClrB = Color.Salmon ' Greater Than

LvItem = New ListViewItem
LvItem.Text = reqWire
LvItem.SubItems.Add(AcVolts)
LvItem.SubItems.Add(AcVoltLoss)
If AcVoltLoss = maxVd Then
' Change Color of Items
lvs = LvItem.SubItems(0) ' Required Wire
lvs.BackColor = nwClrA
lvs = LvItem.SubItems(1) ' Volt Loss
lvs.BackColor = nwClrA
lvs = LvItem.SubItems(2) ' Volt Loss %
lvs.BackColor = nwClrA
Else
lvs = LvItem.SubItems(0) ' Required Wire
lvs.BackColor = nwClrB
lvs = LvItem.SubItems(1) ' Volt Loss
lvs.BackColor = nwClrB
lvs = LvItem.SubItems(2) ' Volt Loss %
lvs.BackColor = nwClrB
End If ' Update ListView
lvResults.Items.Add(LvItem)

So what am I doing wrong??

Thanks in advance!

BruceF
 
J

Jan Hyde (VB MVP)

I've not programmed for a while in VB 2003... but I've decided to modlfiy a
Project I have.

Seems simple enough... I've a List Box... I fill it with about 30 lines of
data (3-4 columns).

What I want to do is to be able to List the ROWS of data either a RED or GREEN
colour depending upon an IF statement.

So... IF X =< myVariable then Row would be GREEN ELSE Row would be RED.

I going to assume you mean listview although you've also
said listbox.

The problem seems to be you want to set the colour of the
listviewitem and not the listview. However you are setting
the colour of the *listview* and so that is what you get.

Try changing the colour of the *listviewitem* (which IIRC
has forecolor and backcolor properties)

J
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

List View Cololurs 1

Top