Results 1 to 25 of 25

Thread: [RESOLVED] ListView not responding to code

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    Resolved [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

  2. #2
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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?

  4. #4
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    Re: ListView not responding to code

    Hi Phil,

    No change with dummy item addition.

    .View = lvwReport

    Name:  New Bitmap Image.jpg
Views: 1480
Size:  14.3 KB

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,522

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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?

    Name:  New Bitmap Image.bmp
Views: 1518
Size:  137.0 KB
    Last edited by JimOldguy; Apr 19th, 2018 at 07:44 AM. Reason: Added Listview Details image.

  8. #8
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,106

    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

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: ListView not responding to code

    Quote Originally Posted by JimOldguy View Post
    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.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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.

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,106

    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.

  12. #12
    Fanatic Member
    Join Date
    Jan 2013
    Posts
    759

    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.

  13. #13

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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!

  14. #14

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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.

  15. #15

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    Unhappy 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...

  16. #16
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,382

    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

  17. #17

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    Re: ListView not responding to code

    Yes, tried both.
    Here's how I tried setting up at design time:
    Name:  New Bitmap Image.jpg
Views: 1649
Size:  59.0 KB

  18. #18
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,382

    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

  19. #19
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,625

    Re: ListView not responding to code

    Quote Originally Posted by JimOldguy View Post
    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.

  20. #20

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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.
    Name:  Run in IDE.jpg
Views: 1517
Size:  59.4 KB

    Wonderful! Or so I thought!

    I then built a .exe file, but when I run that, this is what I see:
    Name:  New Bitmap Image.jpg
Views: 1484
Size:  19.3 KB

    I've tried REGSVR32 mscomctl.ocx, in Admin mode, and that completes without error, but the .exe still won't run!

  21. #21

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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:
    Name:  New Bitmap Image.bmp
Views: 1582
Size:  373.9 KB

    Shouldn't there be just one of each control shown here?

  22. #22
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,382

    Re: ListView not responding to code

    Quote Originally Posted by JimOldguy View Post
    *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

  23. #23

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    Re: ListView not responding to code

    Zvoni, this is a 32Bit PC, so there is only System32.

  24. #24
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,382

    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

  25. #25

    Thread Starter
    Member
    Join Date
    Sep 2015
    Location
    Cambridgeshire, UK
    Posts
    49

    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
  •  



Click Here to Expand Forum to Full Width