Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to change color of item in the list?

C#
listView1.Items[1].SubItems.Add("hello");

how can i change hello to green
Posted
Updated 21-Sep-12 6:23am
v2
Comments
DaveAuld 21-Sep-12 12:25pm    
The whole row or just the subitem?
Member 9092048 21-Sep-12 12:25pm    
whole row
Andrewpeter 21-Sep-12 12:25pm    
You change it in ForeColor property.
Member 9092048 21-Sep-12 12:26pm    
tried listView1.Items[1].SubItems.Add("hello",Color.green); but giving me error add function cannot be overloaded

1 solution

Do something like the code below where cForeColor, cBackColor and fFont are the desired forground color, background color and font respectively.

ListView listView;
ListViewItem item = new ListViewItem("Test");
item.UseItemStyleForSubItems = false;
item.SubItems.Add("Hello", cForeColor, cBackColor, fFont);

Also read this article[^] for more advanced ideas.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900