473,748 Members | 8,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List view colour question

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.
pa************* **@hetnet.nl
*************** ************
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
\namespace WindowsApplicat ion1
{
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.ListView listView1;
private System.Windows. Forms.ColumnHea der columnHeader1;
private System.Windows. Forms.ColumnHea der columnHeader2;
private System.Componen tModel.Containe r components = null;
public Form1()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region
#endregion
static void Main()
{
Application.Run (new Form1());
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
string [] content = new string [4];
string [] show = new string [2];
content [0] = "the cat";
content[1] = "jumped ";
content [2] = "over";
content[3] = "the wall";
int k = -1;
for (int i=0 ;i<2;i++)
{
show [0] = content[++k];
show[1] = content [++k];
ListViewItem list = new ListViewItem(sh ow);
listView1.Items .Add(list);
}
}
}
}

Nov 15 '05 #1
7 1710
You can do
list.ForeColor = Color.Red
(I think thats the spelling, sorry only in newsreader)

You can even set sub items to different colours if you set
list.UseSameFor matForAllSubIte ms (or similar again :) ) to true

HTH
Kieran

"Patrick De Ridder" <00*@000.00> wrote in message
news:10******** *******@evisp-news-01.ops.asmr-01.energis-idc.net...
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.
pa************* **@hetnet.nl
*************** ************
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
\namespace WindowsApplicat ion1
{
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.ListView listView1;
private System.Windows. Forms.ColumnHea der columnHeader1;
private System.Windows. Forms.ColumnHea der columnHeader2;
private System.Componen tModel.Containe r components = null;
public Form1()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region
#endregion
static void Main()
{
Application.Run (new Form1());
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
string [] content = new string [4];
string [] show = new string [2];
content [0] = "the cat";
content[1] = "jumped ";
content [2] = "over";
content[3] = "the wall";
int k = -1;
for (int i=0 ;i<2;i++)
{
show [0] = content[++k];
show[1] = content [++k];
ListViewItem list = new ListViewItem(sh ow);
listView1.Items .Add(list);
}
}
}
}

Nov 15 '05 #2
On Wed, 17 Sep 2003 10:09:42 +0100, "Kieran Benton"
<ki**********@f astmail.fm> wrote:
You can do
list.ForeCol or = Color.Red
This would set al cells to red, I don't want that!
Re my question: I want to be able to set one cell to red under certain
conditions (specifically if the value is negative).
(I think thats the spelling, sorry only in newsreader)

You can even set sub items to different colours if you set
list.UseSameFo rmatForAllSubIt ems (or similar again :) ) to true


I don't understand this.

Please give further help, I am not cracking this problem.

Thanks.
--
Regards,
Patrick.
Nov 15 '05 #3
The correct spelling of the property is:
list.UseItemSty leForSubItems = false

Once this is set you can set individual columns in a row to different
styles.

e.g.

ListViewItem list = listView1.Items .Add( "item" + i.ToString() );
list.UseItemSty leForSubItems = false;
ListViewItem.Li stViewSubItem si = list.SubItems.A dd("Hi");
si.ForeColor = Color.Red;

HTH

Kieran

"Patrick De Ridder" <pa************ ***@hetnet.nl> wrote in message
news:fd******** *************** *********@4ax.c om...
On Wed, 17 Sep 2003 10:09:42 +0100, "Kieran Benton"
<ki**********@f astmail.fm> wrote:
You can do
list.ForeCol or = Color.Red


This would set al cells to red, I don't want that!
Re my question: I want to be able to set one cell to red under certain
conditions (specifically if the value is negative).
(I think thats the spelling, sorry only in newsreader)

You can even set sub items to different colours if you set
list.UseSameFo rmatForAllSubIt ems (or similar again :) ) to true


I don't understand this.

Please give further help, I am not cracking this problem.

Thanks.
--
Regards,
Patrick.

Nov 15 '05 #4
You again omit some information but perhaps this can help you.
With the code below you can fill your content array as you like and
directly assign a background and a foreground color to your content.

After doing so, you set the number of columnheaders you like.
The listview is then filled always from left to right from top to bottom.

This is of course just a minimal version but I think it is easy to expand
this code to be a bit more sophisticated ;-)

private void Form1_Load(obje ct sender, System.EventArg s e)
{
// 1. Prepare content somehow
int contentCount = 12;
Content[] content = new Content[contentCount];
content[0] = new Content("the cat", Color.Black, Color.Aquamarin e);
content[1] = new Content("jumped ", Color.Cornflowe rBlue, Color.Wheat);
content[2] = new Content("over", Color.Black, Color.Beige);
content[3] = new Content("the wall", Color.Cornflowe rBlue, Color.Aquamarin e);
content[4] = new Content("the cat", Color.Black, Color.Aquamarin e);
content[5] = new Content("jumped ", Color.Black, Color.Beige);
content[6] = new Content("over", Color.Yellow, Color.Blue);
content[7] = new Content("the wall", Color.Cornflowe rBlue, Color.Red);
content[8] = new Content("jumped ", Color.Cornflowe rBlue, Color.Red);
content[9] = new Content("the dog", Color.SeaGreen, Color.DarkViole t);
content[10] = new Content("the bird", Color.YellowGre en, Color.SaddleBro wn);
content[11] = new Content("the fox", Color.Black, Color.White);

// Number of cells you want
// = Number of Column Headers
int cellCount = 3;

// Create and add items
for (int i=0; i<contentCount ; i=i+cellCount)
{
ListViewItem lvi = new ListViewItem(co ntent[i].text);
lvi.UseItemStyl eForSubItems = false;
for (int c=1; c<cellCount; c++)
lvi.SubItems.Ad d(content[i+c].text, content[i+c].c1, content[i+c].c2, new Font("Arial", 8));
this.listView1. Items.Add(lvi);
}
}

Hope this helps!
Greetings,
timtos.

"Patrick De Ridder" <00*@000.00> wrote in message news:10******** *******@evisp-news-01.ops.asmr-01.energis-idc.net...
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.
pa************* **@hetnet.nl
*************** ************
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
\namespace WindowsApplicat ion1
{
public class Form1 : System.Windows. Forms.Form
{
private System.Windows. Forms.ListView listView1;
private System.Windows. Forms.ColumnHea der columnHeader1;
private System.Windows. Forms.ColumnHea der columnHeader2;
private System.Componen tModel.Containe r components = null;
public Form1()
{
InitializeCompo nent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region
#endregion
static void Main()
{
Application.Run (new Form1());
}
private void Form1_Load(obje ct sender, System.EventArg s e)
{
string [] content = new string [4];
string [] show = new string [2];
content [0] = "the cat";
content[1] = "jumped ";
content [2] = "over";
content[3] = "the wall";
int k = -1;
for (int i=0 ;i<2;i++)
{
show [0] = content[++k];
show[1] = content [++k];
ListViewItem list = new ListViewItem(sh ow);
listView1.Items .Add(list);
}
}
}
}

Nov 15 '05 #5
On Wed, 17 Sep 2003 13:11:26 +0200, "timtos" <ti****@gmx.d e> wrote:
You again omit some information but perhaps this can help you.
With the code below you can fill your content array as you like and
directly assign a background and a foreground color to your content.

<snipped>

*************** *************** *************** ******
<< I had sent you an email as well >>
*************** *************** *************** ******

Thank you very much.I will study your posting.

For the time being I have done it like this.
(Which is a very simple solution.)

(The lines fit into the example that I have posted above.)

ListViewItem list = new ListViewItem(sh ow);
list.ForeColor = Color.Black;
if(some condition) list.ForeColor = Color.Red;
listView1.Items .Add(list)

It colours the whole line, which is not 100% what I wanted.

I will have a good look at your suggestions now!

Thank you again.
--
Regards,
Patrick.
Nov 15 '05 #6
On Wed, 17 Sep 2003 11:16:33 +0100, "Kieran Benton"
<ki**********@f astmail.fm> wrote:
The correct spelling of the property is:
list.UseItemSt yleForSubItems = false

Once this is set you can set individual columns in a row to different
styles.

e.g.

ListViewItem list = listView1.Items .Add( "item" + i.ToString() );
list.UseItemSt yleForSubItems = false;
ListViewItem.L istViewSubItem si = list.SubItems.A dd("Hi");
si.ForeColor = Color.Red;

<snipped>

Thank you very much.I will study your posting.

For the time being I have done it like this.
(Which is a very simple solution.)

(The lines fit into the example that I have posted above.)

ListViewItem list = new ListViewItem(sh ow);
list.ForeColor = Color.Black;
if(some condition) list.ForeColor = Color.Red;
listView1.Items .Add(list)

It colours the whole line, which is not 100% what I wanted.

I will have a good look at your suggestions now!

Thank you again.
--
Regards,
Patrick.
Nov 15 '05 #7
On Wed, 17 Sep 2003 11:16:33 +0100, "Kieran Benton"
<ki**********@f astmail.fm> wrote:
The correct spelling of the property is:
list.UseItemSt yleForSubItems = false

Once this is set you can set individual columns in a row to different
styles.

e.g.

ListViewItem list = listView1.Items .Add( "item" + i.ToString() );
list.UseItemSt yleForSubItems = false;
ListViewItem.L istViewSubItem si = list.SubItems.A dd("Hi");
si.ForeColor = Color.Red;


Hi Kieran,
Your code works excellently. Thank you very much again.
--
Regards,
Patrick.
Nov 15 '05 #8

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

Similar topics

5
4293
by: Mike | last post by:
How do I extract a list of lists from a user defined function and print the results as strings for each list?
6
1568
by: Dave Pylatuk | last post by:
Hello all. I have a table defined in sql server as follows: ROW_ID (identity) DEPTH_FROM Number (8,3) DEPTH_TO Number (8,3) COLOUR Char(10) With typical data like:
5
1444
by: Karen Bailey | last post by:
Hi, I am attempting to create a view that will rollup or group like, consecutive data. I have created a view using unions, but the statement is extremely slow. Here is example data Colour Table:
2
45081
by: Colin Steadman | last post by:
I have a dropdown list with a couple of dozen entries. I can change the backgroup and text colour. But I cant find the CSS attribute which changes the highlight colour which appears as the mouse moves up or down the list. At the moment its the default deep purple colour you get in any windows app, but I'd like change this to a more suitable colour for my site. This is what I have already - <html>
2
1441
by: Richard Wilde | last post by:
I am trying to change a colour of a listbox item depending on a value in a data view My fields in the dataview are ID Name idCat ListBox1.ValueMember = "ID" ListBox1.DataSource = dv1 ListBox1.DisplayMember = "Name"
6
3118
by: Brad Pears | last post by:
As part of my vb.net 2005 application I would like to automatically select the very first item (index 0) in a listview containing menu items. That way the the listviews "afterselect" event would fired - hence running the code pertaining to that first menu item. How can I do this in code? Thanks, Brad
1
1463
by: Mr. B | last post by:
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.
0
927
by: Mr. B | last post by:
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.
6
1059
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
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9325
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
9249
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8244
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
6796
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
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
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
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.