By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

cell in ListView - bkgrd color not working

P: n/a
How is it ( or can I ) make each subitem reflect the
background color ? In my case the first color is applied
across the row - even though I can read the values back
out correctly ? Thanks ! snippet can be dropped in intact

private void ListViewBroke()
{
listView.View = View.Details;
ArrayList LVcolTitles= new ArrayList();
LVcolTitles.Add("Drive");
LVcolTitles.Add("Cust");
int [] LVcolWidths = {50,50};
for(int i = 0;i< LVcolTitles.Count;i++)
{
listView.Columns.Add(LVcolTitles[i].ToString() ,
LVcolWidths[i],
HorizontalAlignment.Center);
}
ListViewItem item1 = new ListViewItem("D");
item1.SubItems.Add("TEST");
listView.Items.AddRange(
new ListViewItem[] {item1}
);
listView.Refresh();
item1.SubItems[0].BackColor=System.Drawing.Color.Turquoise;
item1.SubItems[1].BackColor=System.Drawing.Color.Tomato;
Console.WriteLine(item1.SubItems[0].Text + " " +
item1.SubItems[1].Text + item1.SubItems[1].BackColor);
listView.Refresh();
}
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Hi Andrew,

Sorry for letting you wait so long.
These 2 days are weekand, so I did not reply to you.
Thank you for your understanding.

I have replied in another post of you.
You should set the UseItemStyleForSubItems property of ListViewItem to
false,
letting the ListViewSubItem use its own style.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "andrewcw" <an************@boeing.com>
| Sender: "andrewcw" <an************@boeing.com>
| Subject: cell in ListView - bkgrd color not working
| Date: Fri, 26 Sep 2003 09:52:44 -0700
| Lines: 30
| Message-ID: <03****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOETpt656dwh/HdThasXRNzzKbn6w==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187573
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| How is it ( or can I ) make each subitem reflect the
| background color ? In my case the first color is applied
| across the row - even though I can read the values back
| out correctly ? Thanks ! snippet can be dropped in intact
|
| private void ListViewBroke()
| {
| listView.View = View.Details;
| ArrayList LVcolTitles= new ArrayList();
| LVcolTitles.Add("Drive");
| LVcolTitles.Add("Cust");
| int [] LVcolWidths = {50,50};
| for(int i = 0;i< LVcolTitles.Count;i++)
| {
| listView.Columns.Add(LVcolTitles[i].ToString() ,
| LVcolWidths[i],
| HorizontalAlignment.Center);
| }
| ListViewItem item1 = new ListViewItem("D");
| item1.SubItems.Add("TEST");
| listView.Items.AddRange(
| new ListViewItem[] {item1}
| );
| listView.Refresh();
| item1.SubItems[0].BackColor=System.Drawing.Color.Turquoise;
| item1.SubItems[1].BackColor=System.Drawing.Color.Tomato;
| Console.WriteLine(item1.SubItems[0].Text + " " +
| item1.SubItems[1].Text + item1.SubItems[1].BackColor);
| listView.Refresh();
| }
|

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.