-
Apr 19th, 2018, 04:37 AM
#1
Thread Starter
Member
[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
-
Apr 19th, 2018, 05:34 AM
#2
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.
-
Apr 19th, 2018, 05:44 AM
#3
Thread Starter
Member
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?
-
Apr 19th, 2018, 06:03 AM
#4
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.
-
Apr 19th, 2018, 06:20 AM
#5
Thread Starter
Member
Re: ListView not responding to code
Hi Phil,
No change with dummy item addition.
.View = lvwReport
-
Apr 19th, 2018, 07:20 AM
#6
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
-
Apr 19th, 2018, 07:39 AM
#7
Thread Starter
Member
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?
Last edited by JimOldguy; Apr 19th, 2018 at 07:44 AM.
Reason: Added Listview Details image.
-
Apr 19th, 2018, 09:00 AM
#8
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
-
Apr 19th, 2018, 09:04 AM
#9
Re: ListView not responding to code
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.
-
Apr 19th, 2018, 09:07 AM
#10
Thread Starter
Member
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.
-
Apr 19th, 2018, 09:18 AM
#11
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.
-
Apr 19th, 2018, 09:21 AM
#12
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.
-
Apr 19th, 2018, 09:21 AM
#13
Thread Starter
Member
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!
-
Apr 19th, 2018, 09:29 AM
#14
Thread Starter
Member
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.
-
Apr 19th, 2018, 10:01 AM
#15
Thread Starter
Member
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...
-
Apr 19th, 2018, 10:02 AM
#16
Re: ListView not responding to code
Have you tried setting up your ListView at Design-Time (and not at Runtime like in your code)?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Apr 19th, 2018, 10:12 AM
#17
Thread Starter
Member
Re: ListView not responding to code
Yes, tried both.
Here's how I tried setting up at design time:
-
Apr 19th, 2018, 10:20 AM
#18
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.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Apr 19th, 2018, 03:52 PM
#19
Re: ListView not responding to code
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.
Last edited by fafalone; Apr 19th, 2018 at 09:04 PM.
-
Apr 20th, 2018, 02:54 AM
#20
Thread Starter
Member
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.
Wonderful! Or so I thought!
I then built a .exe file, but when I run that, this is what I see:
I've tried REGSVR32 mscomctl.ocx, in Admin mode, and that completes without error, but the .exe still won't run!
-
Apr 20th, 2018, 04:11 AM
#21
Thread Starter
Member
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:
Shouldn't there be just one of each control shown here?
-
Apr 20th, 2018, 05:04 AM
#22
Re: ListView not responding to code
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?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Apr 20th, 2018, 05:22 AM
#23
Thread Starter
Member
Re: ListView not responding to code
Zvoni, this is a 32Bit PC, so there is only System32.
-
Apr 20th, 2018, 08:31 AM
#24
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
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Apr 20th, 2018, 10:06 AM
#25
Thread Starter
Member
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|