Click to See Complete Forum and Search --> : Listview.SubItems not exist?


FerrisWheel
April 28th, 2009, 06:03 AM
I was attempting to follow a few tutorials for the ListView control. I am able in the designer to add items and subitems but I want to be able to add them in at runtime. I can do ListView1.Items.Add quite fine but when I attemp to input ListView1.SubItems (As the tutorial suggests) I get an error that is:
'SubItems' is not a member of 'System.Windows.Forms.ListView'

I am using Visual Basic.NET 2008 Express.

sotoasty
April 28th, 2009, 07:21 AM
Subitmes are Items of an Item. ListView1 in your case does not contain subitems. ListView1.Items(0) however would contain SubItems.

I like to add items by using a listview item. This to me makes the code much more readable.


Dim LSingleItem As ListViewItem
LV.Clear()
LV.View = View.Details
LV.GridLines = True
LSingleItem = LV.Items.Add("Text")
LSingleItem.SubItems.Add("SubItem Text")

or.....

LSingleItem = LV.Items(1)
LSingleItem.SubItems.Add("SubItem Text")



Where LV is my listview.