473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

List View Colours

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
Dec 21 '07 #1
1 1451
Mr. B <UR@Home.com>'s wild thoughts were released on Fri, 21
Dec 2007 00:12:48 GMT bearing the following fruit:
>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
>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
--
Jan Hyde

https://mvp.support.microsoft.com/profile/Jan.Hyde
Dec 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Els | last post by:
Hi, I would like an opinion on the following: I have a page which is made up of background-images with transparent linked images in front of it, which on hover show text in CSS popups. Due to...
29
by: lori3laz | last post by:
How do you disable the right click>view source option on web pages so people can't view your coding and copy it? What's the html I need to include in my website to utilize this feature? Thank...
8
by: Doug Laidlaw | last post by:
I tried to grab an image from a Web page the other day. It turned out that the page was made up of three horizontal bands, and part of the image was in each. One band was a JPEG, another was a...
7
by: Patrick De Ridder | last post by:
Below a rather simplistic example of a list view routine. Say I want to have "over" appearing in red on the display, how would I do that? Many thanks, Patrick. patrick.de.ridder@hetnet.nl...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
2
by: mnms | last post by:
Hi, I'm wondering if it's possible "manually" add an extra value to a combobox list. At the moment I have two fields, one "transparent" is a checkbox that lets you define a colour as...
1
by: aman909 | last post by:
Hello, I have a stock control system for fabric that is produced. The stock control has contains details of every colour of fabric that is produced. We have about 40 to 50 different colours. Im...
5
by: Jameson | last post by:
Hi, I have a list of known colours, generated using: Dim colorNames As New System.Collections.Generic.List(Of String) For Each known As KnownColor In .GetValues(GetType(KnownColor)) Dim...
6
by: Yves Dorfsman | last post by:
In the following script, m1() and m2() work fine. I am assuming m2() is faster although I haven't checked that (loops through the list twice instead of once). Now what I am trying to do is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.