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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help adding items to a listview control 2

Status
Not open for further replies.

AncientTiger

Programmer
Jul 5, 2001
238
0
0
US
Just started messing with it, and it's driving me bonkers!

I've got a listview control (Common Controls 6.0), set to REPORT mode, have defined my column headers and am trying to add items to the list but I keep getting "Index out of bounds" errors.

4 columns, labelled A, B, C, & D. I'm just wanting to see how it works, so I set up a simple for/next loop to add stuff:
==============================================

for t = 1 to 5

listview1.listitems(T).listsubitems.add 1, ,"Col A test"
listview1.listitems(T).listsubitems.add 2, ,"Col B test"
listview1.listitems(T).listsubitems.add 3, ,"Col C test"
listview1.listitems(T).listsubitems.add 4, ,"Col D test"

next
==============================================

But it keeps giving me the darned "Index out of bounds" error. I've tried several variations of adding, but still nothing... If someone can just give me a simple for/next code example of how you'd add this stuff it'd be enought to get my wee little brain kickstarted.

Thanks!~


------------------------------------
[yinyang] 18 years of programming, and still learning every day! [yinyang]
 
Try something like this

Dim itm As ListItem

For T = 1 To 5
Set itm = ListView1.ListItems.Add(, "Item" & Cstr(T), "A")
itmX.SubItems(1) = "B"
itmX.SubItems(2) = "C"
itmX.SubItems(3) = "D"
Next T

Hope this helps
 
Try:

Dim MyItem As ListItem
Dim T As Integer
For T = 1 To 5
Set MyItem = ListView1.ListItems.Add(, , "Col A test")
With MyItem
.ListSubItems.Add , , "Col B test"
.ListSubItems.Add , , "Col C test"
.ListSubItems.Add , , "Col D test"
End With
Next

Hope this helps,

Robert
 
Thanks!! That did the trick


------------------------------------
[yinyang] 18 years of programming, and still learning every day! [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top