How to change text of ListViewItem

  • Thread starter Thread starter bthetford
  • Start date Start date
B

bthetford

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?
 
ListView listView;

listView.Items[index].SubItems[index1].Text = "your text";
 
Strange.
I used to get a nullreferenceexception out of that, as well.
I must have had an off-by-one error.

Thanks.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top