?
Solved

ListView help in VB6

Posted on 2003-03-02
24
Medium Priority
?
1,362 Views
Last Modified: 2012-06-21
   Dim lstStuff As ListItem

    Set lstStuff = ListView1.ListItems.add(, , "First Columns")
    lstStuff.SubItems(1) = "Help"
    lstStuff.SubItems(2) = "Third Columns Output"
    lstStuff.SubItems(3) = "Fourth Columns Output"
    Set lstStuff = Nothing

this code only adds the first column, none of the others.  I have created 4 columns.

What is the deal? thanks
0
Comment
Question by:bomax
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
  • 4
  • +6
24 Comments
 
LVL 18

Expert Comment

by:Sethi
ID: 8054638
Set lstStuff.View = lvwReport
0
 

Author Comment

by:bomax
ID: 8054684
It's already set to that using the design-time properties window.
0
 

Expert Comment

by:manduz_griffus
ID: 8054898
try this:

Set lstStuff = ListView1.ListItems.add(, , "First Columns")
lstStuff(1).ListSubItems.add(, , "Help")
lstStuff(1).ListSubItems.add(, , "Third Columns Output")
lstStuff(1).ListSubItems.add(, , "Fourth Columns Output")
Set lstStuff = Nothing

hope this helps.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:bomax
ID: 8054941
manduz - it gives me a syntax error on the second line (lstStuff(1).ListSubItems.add(, , "Help"))
0
 
LVL 1

Expert Comment

by:ksokolowski
ID: 8055127
  Set lstStuff = ListView1.ListItems.add(, , "First Columns")
   lstStuff.ListItems.add(, , "Second Columns")
   lstStuff.ListItems.add(, , "Third Columns")
   lstStuff.SubItems(1) = "Help"
   lstStuff.SubItems(2) = "Third Columns Output"
   lstStuff.SubItems(3) = "Fourth Columns Output"
   Set lstStuff = Nothing
0
 

Expert Comment

by:manduz_griffus
ID: 8055176
this will work:

Set lstStuff = ListView1
lstStuff.ListItems.Add , , "First Columns"
lstStuff.ListItems(1).ListSubItems.Add , , "Help"
lstStuff.ListItems(1).ListSubItems.Add , , "Third Columns Output"
lstStuff.ListItems(1).ListSubItems.Add , , "Fourth Columns Output"
Set lstStuff = Nothing
0
 

Author Comment

by:bomax
ID: 8055271
Neither of those samples worked!  Both times VB6 highlights ".ListItems" and says Method or Data Member not found.

With all these all that is happening is it is adding in "First column" to the first column (on first row) but that is all...nothing else is getting on that darn listview.  :(

I have increased the points for this Q.
0
 

Expert Comment

by:manduz_griffus
ID: 8055334
try this:

declare lstStuff as listview first:

dim lstStuff as listview

Set lstStuff = ListView1
lstStuff.ListItems.Add , , "First Columns"
lstStuff.ListItems(1).ListSubItems.Add , , "Help"
lstStuff.ListItems(1).ListSubItems.Add , , "Third Columns Output"
lstStuff.ListItems(1).ListSubItems.Add , , "Fourth Columns Output"
Set lstStuff = Nothing

hope this works for you!
0
 
LVL 4

Expert Comment

by:AlonHirsch
ID: 8055461
Hi,

Try this code - it works for me in VB6 :
    Dim lstStuff As ListItem

    ' define the 4 columns
    ListView1.ColumnHeaders.Add , , "Column 1"
    ListView1.ColumnHeaders.Add , , "Column 2"
    ListView1.ColumnHeaders.Add , , "Column 3"
    ListView1.ColumnHeaders.Add , , "Column 4"
    ' add a new item with key = Key1 and text = Text1
    Set lstStuff = ListView1.ListItems.Add(, "Key1", "Text1")
    ' add the rest of the subitems for this entry
    lstStuff.SubItems(1) = "Text2"
    lstStuff.SubItems(2) = "Text3"
    lstStuff.SubItems(3) = "Text4"
    ' we are now doen - clean up
    Set lstStuff = Nothing

HTH,
Alon
0
 

Author Comment

by:bomax
ID: 8061689
Okay...I tried both of those and neither one works! Argh!  It only adds the first item but no sub-items (other columns).  Is there ANY settings you are doing at design time other than setting View to 3- lvwReport?
0
 

Expert Comment

by:MadBeef
ID: 8069763
I faced the same problem.   I came across your question when I am looking for a solution here.  There difference is that I am using VB .Net instead.

here is my solution in VB .Net codes. I hope you can try converting it and hopefully it is not causing more confusion.  Please ignore it if you find it totally irrelevent.

ListView1.Clear()
ListView1.Columns.Add("col1", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("col2", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("col3", 80, HorizontalAlignment.Left)
ListView1.Columns.Add("col4", 80, HorizontalAlignment.Left)
Dim oneitem As New ListViewItem()
oneitem.Text = "Text1"
oneitem.SubItems.Add("Text2")
oneitem.SubItems.Add("Text3")
oneitem.SubItems.Add("Text4")
ListView1.Items.Add(oneitem)
oneitem = Nothing


0
 

Author Comment

by:bomax
ID: 8069887
Thanks MadBeef but unfortunately that didn't help me :(  I still have the same problem of only being able to add an item, and no 'subitems'

I have increased points yet again!
0
 
LVL 4

Expert Comment

by:AlonHirsch
ID: 8070003
Hi,

This code definately works - I tried it again this morning!
make sure that the listview is set to Report mode!

Try this code - it works for me in VB6 :
   Dim lstStuff As ListItem

   ' define the 4 columns
   ListView1.ColumnHeaders.Add , , "Column 1"
   ListView1.ColumnHeaders.Add , , "Column 2"
   ListView1.ColumnHeaders.Add , , "Column 3"
   ListView1.ColumnHeaders.Add , , "Column 4"
   ' add a new item with key = Key1 and text = Text1
   Set lstStuff = ListView1.ListItems.Add(, "Key1", "Text1")
   ' add the rest of the subitems for this entry
   lstStuff.SubItems(1) = "Text2"
   lstStuff.SubItems(2) = "Text3"
   lstStuff.SubItems(3) = "Text4"
   ' we are now doen - clean up
   Set lstStuff = Nothing

HTH,
Alon
0
 

Author Comment

by:bomax
ID: 8070080
I pasted the code you supplied into a new project and it worked! But then I pasted it back into my project and it doesn't work! What could be going on here?!?
0
 
LVL 4

Expert Comment

by:AlonHirsch
ID: 8070624
Hi,

I'm not sure - what is you project referencing that is different to the New project ?
Is it the same version of the control ?
Are the design-time settings properties the same ?

If you still do not come right - try create a small project to reproduce the errors you are experiencing.
If you succeed, compare this project with the previous one where the code works and see what the differences are.

HTH,
Alon
0
 

Expert Comment

by:MadBeef
ID: 8072169
you have to set the column width when you are assigning the columnHeader, right?
did you set it to 0 somewhere in your project? try setting it when you assign the header.
0
 

Expert Comment

by:MadBeef
ID: 8072222
I think you can try

ListView1.ColumnHeaders.Add , , "Column 1", 400
  ListView1.ColumnHeaders.Add , , "Column 2", 400
  ListView1.ColumnHeaders.Add , , "Column 3", 400
  ListView1.ColumnHeaders.Add , , "Column 4", 400

hope this help. :)
0
 

Expert Comment

by:manduz_griffus
ID: 8076128
dim lstStuff as listview

Set lstStuff = ListView1
lstStuff.ListItems.Add , , "First Columns"
lstStuff.ListItems(1).ListSubItems.Add , , "Help"
lstStuff.ListItems(1).ListSubItems.Add , , "Third Columns Output"
lstStuff.ListItems(1).ListSubItems.Add , , "Fourth Columns Output"
Set lstStuff = Nothing

include: windows windows common controls 6.0
in your components and use its listview control for this code.

hope this helps!

manduz_griffus
0
 

Author Comment

by:bomax
ID: 8077655
None of these work...and yes my width is not 0 ;)

manduz_griffus: that code won't even run on VB 6...
0
 

Expert Comment

by:manduz_griffus
ID: 8077937
it worked for me. :D
0
 
LVL 4

Expert Comment

by:AlonHirsch
ID: 8079689
Can you zip your project and email it to me - I'll have a look and see if I can find out what is wrong with it.
My email address is wizard@onwe.co.za

Alon
0
 
LVL 3

Accepted Solution

by:
redfordb earned 2000 total points
ID: 8102948
This will generate the column headers...

With lvListView.ColumnHeaders
        .Clear
        .Add , , "First"
        .Add , , "Second"
        .Add , , "Third"
        .Add , , "Fourth"
End With

When you want to add data to the list view, do the following...

'Create the first column "UNIQUEID" must be a string and must be unique in teh listview
    lvListView.ListItems.Add , "UNIQUEID", "1st"
    'Add subitmes to the first column
    lvListView.ListItems("UNIQUEID").ListSubItems.Add , , "2nd"
    lvListView.ListItems("UNIQUEID").ListSubItems.Add , , "3rd"
    lvListView.ListItems("UNIQUEID").ListSubItems.Add , , "4th"
0
 
LVL 5

Expert Comment

by:Netminder
ID: 8251589
A request has been made to delete this question; if there are no objections within 72 hours, the request will be granted.

EXPERTS: Please leave your thoughts on the disposition of this question here.

Netminder
EE Admin
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 8284606
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question