Solved

VB6 ListView not behaving properly

Posted on 2009-06-29
11
985 Views
Last Modified: 2013-12-20
I have a program that works on another computer.  Basically I want to populate a list view and the code is below.  On this computer, I get a Run-time error 380, Invalid property value on the "itmVar.SubItems(1)="DEF" line.  I finished the program on the other computer but now need to use a list view on the computer that's having the problem.  One more tidbit:  This morning I decided to repair VB6 from the CD, and right after I did that, it worked.  I did some other things (non-coding), and then a couple hours later came back to the exact same project, ran it, and got the error again.  I then repaired (no success), uninstalled and reinstalled (still no success).  If anyone has any suggestions, I'd very much appreciate it.  One more thing:  I'm using MS WIndows Common Controls 6.0 (SP6), which is pointing to MSCOMCTL.OCX.

Thanks Experts :-)
Dim itmVar As ListItem

        Set itmVar = Me.lvwClassCode.ListItems.Add()

        itmVar.Text = "ABC"

        itmVar.SubItems(1) = "DEF"

...

Open in new window

0
Comment
Question by:jruhe
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 11

Expert Comment

by:kyodai
ID: 24740376
To me it is absolutely unclear what you want to do here. At first - you can't fix coding error (like runtime error) by re-installing VB or so, runtime error is about always a logical error in your program, it is EXTREMELY unlikely you will fix your source by re-installing VB in any case.

Then this line is a bit odd:

Set itmVar = Me.lvwClassCode.ListItems.Add()

i assume itmVar is some temporary list or so, then you would assume someone assigns an item dimed as a listItem to another list item, not to the "Add" function. To really help you with this line one would need to know what lvwClassCode is and what you want to do with it. But i could be tempted to assume the "Add()" just slipped in here? or did you just mean it vice versa - is ListItems.Add() a function to import list items from a list? Then you would need to declare it rather like Me.lvwClassCode.ListItems.Add(itmVar), but in this example it is obvious this makes no sense as itmVar is empty - it has just been declared in the line above.

The error itself - runtime error 380 - actually just meaned you called a property that doesn't exist. here it is itmVar.SubItems. Subitems is simply not a meber of ListItem. I am really unsure what you think subItem is, but subItem is not available in ListItem. Did you mean ListViewItem?
0
 
LVL 4

Author Comment

by:jruhe
ID: 24740750
The reason I reinstalled VB is because it was intermittently working with the same code.

lvwClassCode is the name of a List View control manually added on my form.

You're partially right -- It's hanging on subitems, but not in the way you may be thinking. . .  Subitems (when using the immediate window after the error occurs) is actually a property off of itmVar (using intellisense, it is a choice from the dropdown).  However, when typing in something like (? itmVar.SubItems(1)) it gives me the same error message.

Thanks!
Joy
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 24743849
try

Set itmVar = Me.lvwClassCode.ListItems.Add(, , "ABC")
itmVar.SubItems(1) = "DEF"
0
 
LVL 4

Author Comment

by:jruhe
ID: 24744491
No--still got the same message.  Thanks for trying though!  Does anyone have an alternative (Microsoft) control that may be as good as or better than List View?  Basically, I want to store data in columns and rows, write some code so that when the user clicks on a column heading, it'll sort by that column.  

It's very frustrating because it works on another computer that I can't use right now--that's why I know it's not the code.  It has to be something with the ocx file, a version of the patch, something happening in the memory that wasn't happening yesterday morning (recall that after I ran the repair yesterday morning, it worked once.  then, I did other things (not with list view--just couldn't get back to it) and then it failed about 3 hours later when I revisited it).

Keep the ideas coming please!

Joy
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 24745593
do you define any column header?

Also set the view to 3-lvwReprt from property
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Author Comment

by:jruhe
ID: 24745731
Keep in mind that the program works on any other computer except this one, and it worked on this one yesterday morning and now it doesn't (although no changes were made to the code).  Therefore, I don't think it's the code.  I think it's the OCX or a version issue or some kind of conflict.  Any thoughts on that?

(In answer to your question, column headers are defined and the view property is set to 3--i tried to keep the sample code as simple as possible to show that even the simplest of commands doesn't work)
0
 
LVL 26

Assisted Solution

by:EDDYKT
EDDYKT earned 100 total points
ID: 24745752
0
 
LVL 22

Accepted Solution

by:
danaseaman earned 400 total points
ID: 24746720
I doubt that there is a problem with the control.
Try this code:

Option Explicit
 

Private Sub Form_Load()
 

   Dim itmVar  As ListItem

   lvwClassCode.View = lvwReport

   lvwClassCode.ColumnHeaders.Add , , "MainItem"

   lvwClassCode.ColumnHeaders.Add , , "SubItem 1"

   Set itmVar = Me.lvwClassCode.ListItems.Add(, , "ABC")

   itmVar.SubItems(1) = "DEF"
 

End Sub

Open in new window

0
 
LVL 4

Author Comment

by:jruhe
ID: 24748996
EDDYKT & danaseaman--I've got another fire right now so I need to put this on the back burner 'til tomorrow.  I'll try both of your suggestions then (dana's first, then EDD's, to be sure that one doesn't fix the other).
Thanks
0
 
LVL 4

Author Comment

by:jruhe
ID: 24753687
To Dana--to my happy surprise, your solution worked.  Obviously the program that I am using has a lot more to it than what I showed, including a ResetData and a RefreshData sub, as well as other subroutines.  

Here's the thing:  Same code, different computer--doesn't work.  AND, on the bad computer, two days ago it worked for about 5 minutes (and I didn't change any code) after I did a repair on the VB Install.  So I went ahead to the site that EDDYKT provided.  I downloaded the msi file and am getting "Could not access network location Tools\VB\Controls\Controls_Backup."  So I'm going to stick with Dana's solution, but I'm going to give EDDY points as well because I think the solution will work into the future.  

Before I close this issue:  Dana (or anyone):  Do you have any idea why it would have:
1. Not worked as coded on the laptop but would work on another machine
2. Worked after I ran the repair install on VB (no modifications to the code)
3. Stopped working about 3 hours later (no modifications to the code)
4. Continues working on all other machines it's run on except this one

Thanks all.  Will close the issue today.

JR
0
 
LVL 22

Assisted Solution

by:danaseaman
danaseaman earned 400 total points
ID: 24756525
My best guess is that MsComCtl.ocx is OK and something in your code is resetting/removing your columns.
You can test this in your application by adding this line of code before you add subitems:

Debug.Print "ColumnHeaders Count", lvwClassCode.ColumnHeaders.Count

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now