views:

35

answers:

1

Hi All,

I'm a bit confused by a few tutorials that I read about the ListView.

I have a ListView control and on the left hand side should be a name, and to the right of that name should be like another column with some more text in it. For example:

ListView:

jason     blah blah blah  
item2     more blahs  
item3     jupiter  
item4     uranus  

How can this be done? Is there a simple way of doing this?

Thank you

+2  A: 

Use the Columns header collection to add the columns such as

  • Column #1
  • Column #2
  • Column #3

then use the ListViewItem's collection to set the values of the columns such this

ListViewItem lvi = new ListViewItem("foo");
lvi.Add("bar");
lvi.Add("baz");
listview.Items.Add(lvi);

Now, you will have "foo", "bar" and "baz" respectively under the columns "Column #1", "Column #2" and "Column #3" respectively.

You will find the Column collection from within the Properties tool box for the listview. Be sure you set the view type to 'Details' to see this effect.

tommieb75
Excellent. Thank you for that. In the 2 tutorials i read tonight, the code was so messy and there were comments scattered all over the place! Very confusing
lucifer
ListViewItem (lvi) no longer contains method: "Add".
lucifer
Use lvi.SubItems.Add("foobar");
Jay