Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1525
  • Last Modified:

ListView help in VB6

   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
bomax
Asked:
bomax
  • 7
  • 5
  • 4
  • +6
1 Solution
 
SethiCommented:
Set lstStuff.View = lvwReport
0
 
bomaxAuthor Commented:
It's already set to that using the design-time properties window.
0
 
manduz_griffusCommented:
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!

 
bomaxAuthor Commented:
manduz - it gives me a syntax error on the second line (lstStuff(1).ListSubItems.add(, , "Help"))
0
 
ksokolowskiCommented:
  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
 
manduz_griffusCommented:
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
 
bomaxAuthor Commented:
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
 
manduz_griffusCommented:
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
 
Alon HirschSoftware Development ManagerCommented:
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
 
bomaxAuthor Commented:
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
 
MadBeefCommented:
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
 
bomaxAuthor Commented:
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
 
Alon HirschSoftware Development ManagerCommented:
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
 
bomaxAuthor Commented:
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
 
Alon HirschSoftware Development ManagerCommented:
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
 
MadBeefCommented:
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
 
MadBeefCommented:
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
 
manduz_griffusCommented:
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
 
bomaxAuthor Commented:
None of these work...and yes my width is not 0 ;)

manduz_griffus: that code won't even run on VB 6...
0
 
manduz_griffusCommented:
it worked for me. :D
0
 
Alon HirschSoftware Development ManagerCommented:
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
 
redfordbCommented:
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
 
NetminderCommented:
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
 
MindphaserCommented:
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Technology Partners: 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!

  • 7
  • 5
  • 4
  • +6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now