-
[RESOLVED] ListView not responding to code
I have an app that loads a ListView with a list of applications currently installed on the PC, and their uninstall string commands.
However, try as I might, I cannot get the ListView to respond to any of my code commands, except for resizing when the main form is resized.
Here's the code that sets up the ListView:
Code:
With Me.ListView1
.Width = Me.Width - 500
.Height = Me.Height - 1400
.Top = 840
.View = lvwReport
.GridLines = True
.FullRowSelect = True
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Application Name", 5000, lvwColumnLeft
.ColumnHeaders.Add , , "Uninstall String extracted from Registry", 70000, lvwColumnLeft
End With
This is how the data is loaded:
Code:
If strValue2 <> "" Then
Set lstItem = Me.ListView1.ListItems.Add() ' Add items and subitems to list control.
lstItem.Text = strValue1
lstItem.SubItems(1) = strValue2
End If
The result is just a ListView that fills the main form, with just one entry, the first item loaded.
There are no column headers, and no gridlines, either.
The resize code, which works, is this:
Code:
Private Sub Form_Resize()
With Me.ListView1
.Width = Me.Width - 500
.Height = Me.Height - 1400
End With
End Sub
I've tried regsvr32 mscomctl.ocx, but that, when run as Administrator, completes without error.
I'm running this under Windows 10, one PC is 64Bit, another is 32Bit.
Can anyone see where I'm going wrong? This is driving me nuts!
Jim
-
Re: ListView not responding to code
Let's see some more of the "data loading" code - like the loop construct that's driving it.
When you debug the code, does it pass through Me.ListView1.ListItems.Add() more than once?
Regards, Phill W.
-
Re: ListView not responding to code
Hi Phil,
Yes, typically there are about 55 iterations through the loop, depending upon what software has been installed on the PC.
This is all the relevant code:
Code:
With Me.ListView1
.Width = Me.Width - 500
.Height = Me.Height - 1400
.Top = 840
.View = lvwReport
.GridLines = True
.FullRowSelect = True
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Application Name", 5000, lvwColumnLeft
.ColumnHeaders.Add , , "Uninstall String extracted from Registry", 70000, lvwColumnLeft
End With
Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName"
objReg.GetStringValue HKLM, strKeyPath, "ComputerName", strPCName
handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")
If handle > 0 Then 'IsWow64Process function exists
IsWow64Process GetCurrentProcess(), is64bit 'determine if we are running under Wow64
End If
If is64bit Then
strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
Else
strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
End If
objReg.EnumKey HKLM, strKeyPath, arrSubKeys
For Each strSubKey In arrSubKeys
strValue1 = "": strValue2 = ""
objReg.GetStringValue HKLM, strKeyPath & strSubKey, "DisplayName", strValue1
If strValue1 <> "" And (InStr(1, strValue1, "Update")) = 0 And (InStr(1, strValue1, "Service Pack")) = 0 And (InStr(1, strValue1, "Hotfix")) = 0 Then
objReg.GetStringValue HKLM, strKeyPath & strSubKey, "UninstallString", strValue2
If strValue2 <> "" Then
Set lstItem = Me.ListView1.ListItems.Add() ' Add items and subitems to list control.
lstItem.Text = strValue1
lstItem.SubItems(1) = strValue2
End If
End If
Next
I hope this is understandable?
-
Re: ListView not responding to code
What if you try adding "dummy" items into the listview at the same time?
Code:
If strValue2 <> "" Then
Set lstItem = Me.ListView1.ListItems.Add() ' Add items and subitems to list control.
lstItem.Text = strValue1
lstItem.SubItems(1) = strValue2
End If
Me.ListView1.ListItems.Add( "DUMMY " & Format$( Me.ListView1.ListItems.Count ) )
Do those appear?
What's the .View property set to? (or is that a .Net thing?)
Regards, Phill W.
-
1 Attachment(s)
Re: ListView not responding to code
Hi Phil,
No change with dummy item addition.
.View = lvwReport
Attachment 158411
-
Re: ListView not responding to code
Set a breakpoint at the top of the code and see if you're even hitting it... First instinct is that the code isn't even being reached.
-tg
-
1 Attachment(s)
Re: ListView not responding to code
TG,
Been there, done that.
Stepping through the code with F8, every line gets executed as expected.
I'm concerned that the "initialisation section", although executed, has no effect on the ListView at all. Indeed, even setting the relevant sections in the ListView1 properties pages has no effect.
Have I got a faulty copy of something or other?
Attachment 158413
-
Re: ListView not responding to code
What happens if you start a new blank project, add a ListView to the form, and paste your code below into Form_Load?
Code:
With Me.ListView1
.Width = Me.Width - 500
.Height = Me.Height - 1400
.Top = 840
.View = lvwReport
.GridLines = True
.FullRowSelect = True
.ListItems.Clear
.ColumnHeaders.Clear
.ColumnHeaders.Add , , "Application Name", 5000, lvwColumnLeft
.ColumnHeaders.Add , , "Uninstall String extracted from Registry", 70000, lvwColumnLeft
End With
-
Re: ListView not responding to code
Quote:
Originally Posted by
JimOldguy
I'm concerned that the "initialisation section", although executed, has no effect on the ListView at all. Indeed, even setting the relevant sections in the ListView1 properties pages has no effect.
Have I got a faulty copy of something or other?
There is a property to hide column headers, correct? Ensure that isn't set to true
Is it possible that the subitem string you are adding is prefixed with a carriage return or line feed, null character or something else that would prevent it from being displayed in the subitem? Have you tried to manually supply a test subitem value? If not, try that and see if the subitem is shown.
-
Re: ListView not responding to code
OptionBase,
That produces just a totally blank ListView.
LaVolpe,
Yes, I've checked hide column headers, etc.
I've also tried adding a simple "Dummy Text" item, all to no avail.
-
Re: ListView not responding to code
You make reference to the mscomctl.ocx, and based on your About screenshot above, you are presumably using a ListView from the Microsoft Windows Common Controls 6.0 (SP6) component.
What happens if, in your blank test project, you instead use a ListView from the Microsoft Windows Common Controls 5.0 component? This ties to the ComCtl32.ocx file instead.
-
Re: ListView not responding to code
OK, let's get the really daft stuff out of the way ...
- Have you got more than one ListView?
You haven't somehow created a ListView2 (or a ListView1(1)) that sits "over the top" of ListView1? - Have you got any "On Error" statements that you haven't shown us?
Regards, Phill W.
-
Re: ListView not responding to code
OB,
Yes, it works if I use the older, version 5.0 component, but that doesn't support checkboxes, which I need!
Highly frustrating!
-
Re: ListView not responding to code
Phil,
Only one ListView.
No "On Errors". (I did have "On Error Resume Next", but I took that out to see if any errors were flagged, but nothing.
-
Re: ListView not responding to code
I am now leaning towards the conclusion, somewhat inevitably, that there's something adrift in my VB6 installation.
(It's Visual Studio 6, actually, but I don't think that makes any difference here.)
I guess I'll just have to bite the bullet and do a re-install this weekend, if the kids will leave me alone long enough!
I'll report back here the outcome...
-
Re: ListView not responding to code
Have you tried setting up your ListView at Design-Time (and not at Runtime like in your code)?
-
1 Attachment(s)
Re: ListView not responding to code
Yes, tried both.
Here's how I tried setting up at design time:
Attachment 158415
-
Re: ListView not responding to code
Hmm, can't see anything wrong with it.
Just to check: Can you place two standard ListBoxes on your Form, and then add strValue1 to the first, and strValue2 to the second during your loop?
It's to find out, if it's your ListView or if it's your Loop/Registry-stuff.
-
Re: ListView not responding to code
Quote:
Originally Posted by
JimOldguy
OB,
Yes, it works if I use the older, version 5.0 component, but that doesn't support checkboxes, which I need!
Highly frustrating!
The 5.0 control absolutely does support checkboxes, you just have to set them with API. Add the LVS_EX_CHECKBOXES style, then also here's some macros to get/set the state:
Code:
'ListView_SetExtendedListViewStyleEx LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES
Public Function ListView_SetExtendedListViewStyleEx(hwndLV As Long, dwMask As Long, dw As Long) As Long
ListView_SetExtendedListViewStyleEx = SendMessage(hwndLV, LVM_SETEXTENDEDLISTVIEWSTYLE,
ByVal dwMask, ByVal dw)
End Function
Public Function ListView_GetCheckState(hwndLV As Long, iIndex As Long) As Long ' updated
Dim dwState As Long
dwState = SendMessage(hwndLV, LVM_GETITEMSTATE, ByVal iIndex, ByVal LVIS_STATEIMAGEMASK)
ListView_GetCheckState = (dwState \ 2 ^ 12) - 1
End Function
Public Function ListView_SetCheckState(hwndLV As Long, i As Long, fCheck As Long) As Long
ListView_SetCheckState = ListView_SetItemState(hwndLV, i, IndexToStateImageMask(IIf(fCheck, 2, 1)), LVIS_STATEIMAGEMASK)
End Function
Public Function ListView_SetItemState(hwndLV As Long, i As Long, State As LVITEM_state, Mask As LVITEM_state) As Boolean
Dim lvi As LVITEM
lvi.State = State
lvi.StateMask = Mask
ListView_SetItemState = SendMessage(hwndLV, LVM_SETITEMSTATE, ByVal i, lvi)
End Function
Public Function IndexToStateImageMask(ByVal Index As Long) As Long
IndexToStateImageMask = Index * (2 ^ 12)
End Function
It's like this for all features. The 5.0 control supports every single feature of the 6.0 control (and tons of features the 6.0 doesn't support), you just need a few API calls to do it.
-
2 Attachment(s)
Re: ListView not responding to code
Good morning,
(Well, it is here, in UK!)
Thank you, Fafalone, for all that info. I'll look into using that as my Plan B.
In the meantime...
I have just run the code here on my 32Bit Windows 10 PC at home.
In the IDE, it runs perfectly! All ListView features are correct.
Attachment 158423
Wonderful! Or so I thought!
I then built a .exe file, but when I run that, this is what I see:
Attachment 158425
I've tried REGSVR32 mscomctl.ocx, in Admin mode, and that completes without error, but the .exe still won't run!:(
-
1 Attachment(s)
Re: ListView not responding to code
I've now re-installed VB6 on my 32Bit PC, but that has made no difference.
However, I have just noticed something slightly odd:
When I add MS Windows Common Controls 6.0 (SP6) to the components, I seem to get multiple instances in the toolbox.
See this:
Attachment 158427
Shouldn't there be just one of each control shown here?
-
Re: ListView not responding to code
Quote:
Originally Posted by
JimOldguy
*snipp*
I've tried REGSVR32 mscomctl.ocx, in Admin mode, and that completes without error, but the .exe still won't run!:(
Have you run regsvr32 in both folders (System32 and SysWow64)/Is the OCX in both Folders?
-
Re: ListView not responding to code
Zvoni, this is a 32Bit PC, so there is only System32.
-
Re: ListView not responding to code
I remember an issue with ListView with some Win-Updates disabling the control/ocx in the registry.
the ocx is correctly installed and registered, but disabled in the registry.
but for the life of me i can't remember how i solved that.
it had to do something with a tool, where you can enable/disable controls in the registry.
search the forums here. If i remember correctly, there have been some threads with similiar problems with Listview
-
Re: ListView not responding to code
OK, guys,
Thanks for all your help and suggestions.
I've been down the hard road, and done a Windows 10 Reset!
Now, having re-installed VB6, all is well!
Must have been something corrupted, somewhere.
Fortunately, Windows 10 Reset only takes an hour or so, and you get back to a nice clean PC!
Now I just have to re-install all my apps!
Anyway, thanks again to all concerned.