PC Review


Reply
Thread Tools Rate Thread

How to change text of ListViewItem

 
 
bthetford
Guest
Posts: n/a
 
      23rd Feb 2007
I have a ListView with 4 columns that shows in details mode.

How do I change the text of one of the columns of a specific item if I
know the index I want to change at?

mylistview.Items[index].Tag
returns a null reference exception if I attempt to use it.

I am displaying data that changes in real time and needs to have
certain columns update when a separate thread invokes an
UpdateMyColumn(int index, string newText) method on the form.

Should I be using a different control, instead?

 
Reply With Quote
 
 
 
 
Ashot Geodakov
Guest
Posts: n/a
 
      23rd Feb 2007
ListView listView;

listView.Items[index].SubItems[index1].Text = "your text";

"bthetford" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have a ListView with 4 columns that shows in details mode.
>
> How do I change the text of one of the columns of a specific item if I
> know the index I want to change at?
>
> mylistview.Items[index].Tag
> returns a null reference exception if I attempt to use it.
>
> I am displaying data that changes in real time and needs to have
> certain columns update when a separate thread invokes an
> UpdateMyColumn(int index, string newText) method on the form.
>
> Should I be using a different control, instead?
>



 
Reply With Quote
 
bthetford
Guest
Posts: n/a
 
      24th Feb 2007
Strange.
I used to get a nullreferenceexception out of that, as well.
I must have had an off-by-one error.

Thanks.

 
Reply With Quote
 
Ashot Geodakov
Guest
Posts: n/a
 
      24th Feb 2007
Well, there must be no SubItems added to the ListItem.Subitems collection.

It's not enough to just create columns in the ListView. For each added item
you need to

ListView.Items[index].SubItems.Add( "lalala" );

Then you can change their text as described.

"bthetford" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Strange.
> I used to get a nullreferenceexception out of that, as well.
> I must have had an off-by-one error.
>
> Thanks.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ListView.Items.Add(ListViewItem) returns ListViewItem reference instead of the Index as integer? Eric Newton Microsoft Dot NET Framework Forms 3 8th Jan 2004 09:56 AM
Re: Change the background colour of a ListViewItem? ToddT Microsoft VB .NET 0 7th Jan 2004 07:17 PM
Re: Change the background colour of a ListViewItem? One Handed Man [ OHM# ] Microsoft VB .NET 0 7th Jan 2004 07:04 PM
Re: Change the background colour of a ListViewItem? Herfried K. Wagner [MVP] Microsoft VB .NET 0 7th Jan 2004 06:53 PM
Change the background colour of a ListViewItem? Robin Tucker Microsoft VB .NET 0 7th Jan 2004 06:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:08 AM.