Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listview - subitems 1

Status
Not open for further replies.

cbsm

Programmer
Oct 3, 2002
229
FR
Hi,
I am trying to add a listview to my code ...
Here is my code so far :

Sub PopulateList()
Dim ListOEM As ListItem

lstvOEM.View = lvwList
Set ListOEM = lstvOEM.ListItems.Add(, ,"This is a test1")
ListOEM.SubItems(0) = "This is a test2"
Set ListOEM = Nothing

end sub
But i get an error at
ListOEM.SubItems(0) = "This is a test2"

Invalid property value

I checked but can't find what I am doing wrong ?

(I am using VB6 - SP6)

Thanks
 
The SubItems() array is 1-based.

The first subitem has the index 1, so you should use;

[tt]ListOEM.SubItems(1) = "This is a test2"[/tt]
 
Thanks Hypetia,
But I tried this before - still the same error ...
 
Is there a reason the variable you declare is called ListOEM but then you have this code

lstvOEM.View = lvwList

which uses a different variable?

Transcend
[gorgeous]
 
I decided to work with treeview instead of listview - which actualy correspond better to what i'd like to do.
I still be curious though, to know why this doens't work ...
 
Hi,

the problem is that you need to setup the listview as having columns in the 'columnheader' tab of its property-page. When you add a subitem to an item in a listview while it does not have a corresponding column it will give you the Invalid Property Value error. Subitem(1) will go in column 2, Subitem(2) in column 3, and so on. Trying to access a subitem that cannot exist because there's not column for it will give you the error.

__________________
code is enduring
 
The subite property is deprecated anyway. You should be using the the ListSubitems collection i.e.
Code:
Dim ListOEM As ListItem
 
lstvOEM.View = lvwList
Set ListOEM = lstvOEM.ListItems.Add(, ,"This is a test1")
ListOEM.ListSubItems.add ,, "This is a test2"
Set ListOEM = Nothing

end sub

Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top