473,473 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Create 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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
\namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs 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(show);
listView1.Items.Add(list);
}
}
}
}

Nov 15 '05 #1
7 1688
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.UseSameFormatForAllSubItems (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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
\namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs 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(show);
listView1.Items.Add(list);
}
}
}
}

Nov 15 '05 #2
On Wed, 17 Sep 2003 10:09:42 +0100, "Kieran Benton"
<ki**********@fastmail.fm> wrote:
You can do
list.ForeColor = 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.UseSameFormatForAllSubItems (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.UseItemStyleForSubItems = 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.UseItemStyleForSubItems = false;
ListViewItem.ListViewSubItem si = list.SubItems.Add("Hi");
si.ForeColor = Color.Red;

HTH

Kieran

"Patrick De Ridder" <pa***************@hetnet.nl> wrote in message
news:fd********************************@4ax.com...
On Wed, 17 Sep 2003 10:09:42 +0100, "Kieran Benton"
<ki**********@fastmail.fm> wrote:
You can do
list.ForeColor = 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.UseSameFormatForAllSubItems (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(object sender, System.EventArgs e)
{
// 1. Prepare content somehow
int contentCount = 12;
Content[] content = new Content[contentCount];
content[0] = new Content("the cat", Color.Black, Color.Aquamarine);
content[1] = new Content("jumped", Color.CornflowerBlue, Color.Wheat);
content[2] = new Content("over", Color.Black, Color.Beige);
content[3] = new Content("the wall", Color.CornflowerBlue, Color.Aquamarine);
content[4] = new Content("the cat", Color.Black, Color.Aquamarine);
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.CornflowerBlue, Color.Red);
content[8] = new Content("jumped", Color.CornflowerBlue, Color.Red);
content[9] = new Content("the dog", Color.SeaGreen, Color.DarkViolet);
content[10] = new Content("the bird", Color.YellowGreen, Color.SaddleBrown);
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(content[i].text);
lvi.UseItemStyleForSubItems = false;
for (int c=1; c<cellCount; c++)
lvi.SubItems.Add(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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
\namespace WindowsApplication1
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.ComponentModel.Container components = null;
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region
#endregion
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs 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(show);
listView1.Items.Add(list);
}
}
}
}

Nov 15 '05 #5
On Wed, 17 Sep 2003 13:11:26 +0200, "timtos" <ti****@gmx.de> 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(show);
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**********@fastmail.fm> wrote:
The correct spelling of the property is:
list.UseItemStyleForSubItems = 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.UseItemStyleForSubItems = false;
ListViewItem.ListViewSubItem si = list.SubItems.Add("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(show);
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**********@fastmail.fm> wrote:
The correct spelling of the property is:
list.UseItemStyleForSubItems = 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.UseItemStyleForSubItems = false;
ListViewItem.ListViewSubItem si = list.SubItems.Add("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
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
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) ...
5
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...
2
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...
2
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...
6
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...
1
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...
0
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...
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: 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
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...
0
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,...
0
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,...
1
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.