473,699 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Li stViewSubItem
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 1459
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.Li stViewSubItem
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
3949
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 appropriate alt text, anyone viewing the page with images turned off, will see the alt text instead, and on hover will see the popups.
29
9774
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 you.
8
2251
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 GIF and I have forgotten what the main page was. Apart from lining up the parts of the image, there was no discrepancy in colours between the two formats. Is that what "Web-safe" means? I thought that it just meant that the colours would be the...
7
1706
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 *************************** using System; using System.Drawing; using System.Collections;
0
3237
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 way... here is my code on how I did it to help anyone starting out get an idea of how to use virtual mode in ..NET 2.0 Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared
2
2897
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 transparent, and the other is a combobox called "Colours" that lists colours. The values in Colours depend on two differnet querys each based on tblColour. the query qTransparentColours shows all colours where the field Transparent is true and qSolidColours...
1
1377
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 now adding a ordering processing system to it as well. In this order system we have certain clients that only ever order certain colours. For example one client will only ever order 5 colours we produce. I would like to produce a form, which only...
5
4032
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 specific As Color = Color.FromKnownColor(known)
6
1055
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 something like m3(). As currently written it does not work, and I have tried different ways, but I haven't managed to make it work. Is there a possibility ? Or is m2() the optimum ?
0
8618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8916
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7752
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2348
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.