cell properties in ListView - not updated in display

  • Thread starter Thread starter andrewcw
  • Start date Start date
A

andrewcw

I have a simple winform with the following code.
But although I can read back the info, the display fails
to provide the text or the cell background color changes.

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.ToString() ,
LVcolWidths, HorizontalAlignment.Center);
} // columns load, data and color missing !!!
ListViewItem item1 = new ListViewItem("D");
item1.SubItems.Add("TEST");
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);
listView.Refresh();
}


Any ideas ? Thanks
 
Hi Andrew,

I think you missed the statement of adding the ListViewItem into the
ListView control.
You should add "listView.Items.Add(item1);" before the last refresh line.

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" <[email protected]>
| Sender: "andrewcw" <[email protected]>
| Subject: cell properties in ListView - not updated in display
| Date: Thu, 25 Sep 2003 12:56:45 -0700
| Lines: 28
| Message-ID: <[email protected]>
| 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: AcODnyXg7bcYXr9oTHuBpiZJwtPWlA==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187397
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have a simple winform with the following code.
| But although I can read back the info, the display fails
| to provide the text or the cell background color changes.
|
| 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.ToString() ,
| LVcolWidths, HorizontalAlignment.Center);
| } // columns load, data and color missing !!!
| ListViewItem item1 = new ListViewItem("D");
| item1.SubItems.Add("TEST");
| 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);
| listView.Refresh();
| }
|
|
| Any ideas ? Thanks
 
Thanks - but it raises a new question ..

Why does only the first color show and why is it applied
across the row - instead of the cell item ??

Thanks Andrew
 
Hi Andrew,

You should set the UseItemStyleForSubItems property of ListViewItem to
false.
This will let the ListViewSubItem use its own style.

If there is still any question, please feel free to let me know. I am glad
to work with you.
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" <[email protected]>
| Sender: "andrewcw" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: RE: cell properties in ListView - not updated in display
| Date: Fri, 26 Sep 2003 09:47:29 -0700
| Lines: 82
| Message-ID: <[email protected]>
| 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: AcOETd+W/3XCc5j4S/SyrBTjyWRsTA==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187572
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks - but it raises a new question ..
|
| Why does only the first color show and why is it applied
| across the row - instead of the cell item ??
|
| Thanks Andrew
| >-----Original Message-----
| >
| >Hi Andrew,
| >
| >I think you missed the statement of adding the
| ListViewItem into the
| >ListView control.
| >You should add "listView.Items.Add(item1);" before the
| last refresh line.
| >
| >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" <[email protected]>
| >| Sender: "andrewcw" <[email protected]>
| >| Subject: cell properties in ListView - not updated in
| display
| >| Date: Thu, 25 Sep 2003 12:56:45 -0700
| >| Lines: 28
| >| Message-ID: <[email protected]>
| >| 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: AcODnyXg7bcYXr9oTHuBpiZJwtPWlA==
| >| Newsgroups: microsoft.public.dotnet.languages.csharp
| >| Path: cpmsftngxa06.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:187397
| >| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| >| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| >|
| >| I have a simple winform with the following code.
| >| But although I can read back the info, the display fails
| >| to provide the text or the cell background color
| changes.
| >|
| >| 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.ToString() ,
| >| LVcolWidths, HorizontalAlignment.Center);
| >| } // columns load, data and color missing !!!
| >| ListViewItem item1 = new ListViewItem("D");
| >| item1.SubItems.Add("TEST");
| >| 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);
| >| listView.Refresh();
| >| }
| >|
| >|
| >| Any ideas ? Thanks
| >
| >
| >
| >.
| >
|
 
Back
Top