1

I want to have a ListView that in addition to "item.Text" and "item.Name" should have some more custom properties for each ListViewItem.

How can I do that (syntax and etc...)

Also is it possible to set a List<string> or List<class> as a property of an listview item?

Thanks.

1
  • 1
    Avoid using a control as a collection class. Separate the data from the view. Commented Oct 14, 2011 at 10:27

1 Answer 1

4

You can inherit from ListViewItem class.

public class MyListViewItem : ListViewItem {
    public List<object> Tags {get; set;}
}

// ... elsewhere

var item = new MyListViewItem {
    Text = "Hello world!",
    Tags = new List<object> { null, true, 15, "asdf", 78.7 }
};
this.listView1.Items.Add(item);
Sign up to request clarification or add additional context in comments.

3 Comments

also mention how to get item... MyListViewItem myItem = (MyListViewItem)listView1.Items[0];
hmm, I was thinking of the whole ListView class, not the item only. will this do the same thing? I want all the items have same proprety attributes.
The ListViewItem is another class than ListView. You can not "add property" to every item in listview. The every item can be instance of different class derived from ListView.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.