Sign in to follow this  
Followers 0
KongMD

[SOLVED] Checkbox disappears after SetItemState

8 posts in this topic

#1 ·  Posted (edited)

My goal is to uncheck a checkbox that's inside of a SysListView32. I assume I have something wrong with the State parameter (have tried several values), because when this code is executed, the checkbox disappears entirely. Clicking on the control (not the checkbox) once shows an unchecked box.

_GUICtrlListView_SetItemState($listview, $i, 0, $LVIS_STATEIMAGEMASK)
Edited by KongMD

Share this post


Link to post
Share on other sites



Try using $GUI_UNCHECKED for the state instead of $LVIS_STATEIMAGEMASK.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

That doesn't work, unfortunately. The variable I assigned to the expression returned "True", so I must have the $iState parameter wrong (note: there's an $iState and also an $iStateMask parameter) I can't determine what to put there... The helpfile doesn't give any possible values, strangely. Here's what I've tried so far:

$test = _GUICtrlListView_SetItemState($listview, $i, $GUI_UNCHECKED, $GUI_UNCHECKED)
$test = _GUICtrlListView_SetItemState($listview, $i, $GUI_CHECKED, $GUI_UNCHECKED)
$test = _GUICtrlListView_SetItemState($listview, $i, 0, $GUI_UNCHECKED)

Share this post


Link to post
Share on other sites

Have you tried _GUICtrlListView_SetItemChecked?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Just tried that now - test var returns true, but box stays checked. I dug up an old thread and got an idea - I can just ControlSend the {SPACE} command to the control! The problem is that it always toggles the checkbox of the first item in the list. I have the desired item selected already - how do I put the focus on the item that's currently selected in a SysListView32 control?

Edited by KongMD

Share this post


Link to post
Share on other sites

When you tried that command I gave you, what was the format you used to try and uncheck it? Also, can you post a reproducer script that shows the problem? It's easier to figure out what's going wrong if we know what you're trying to do.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Sure, I'd be happy to. Here's the function. The code segment we've been working with is inside the conditional "If $iniVal <> "NotFound" AND $iniVal = 0 Then"

Func reDisableEntries($isServices)
        
    If $isServices = 1 Then
        ;Click services
        _GUICtrlTab_ClickTab($hTab, 2)
        Sleep(50)
        
        ;Check the hide
        ControlCommand($configWin, "", "Button3", "Check")
        Sleep(50)
    Else
        ;Click startup
        _GUICtrlTab_ClickTab($hTab, 3)
        Sleep(50)
    EndIf

    ;Restore service states back to user's custom setting
    ControlFocus($configWin, "", "List1")
    Sleep(50)
    
    Local $listview = ControlGetHandle ( $configWin, "", "List1" )
    Local $totalItems = ControlListView ($configWin, "", $listview, "GetItemCount")
    Local $iniVal = 1 ;default
    
    For $i = 0 To ($totalItems - 1)
        ControlListView($configWin, "", $listview, "SelectClear")
        ControlListView($configWin, "", $listview, "Select", $i)
        
        $indexSelected = ControlListView($configWin, "", $listview, "GetSelected")
        $itemText = ControlListView($configWin, "", $listview, "GetText", $indexSelected, 0)
        $itemState = getListItemState($listview, $i)
        
        ;MsgBox(64, $i, $itemText & " - " & $itemState)

        If $isServices = 1 Then
            ;add service name to an .ini file
            $iniVal = IniRead (@AppDataDir & "SelectiveStartup.ini", "Disabled Services", $itemText, "NotFound")
        ElseIf $isServices = 0 Then
        ;add startup program name to an .ini file
            $iniVal = IniRead (@AppDataDir & "SelectiveStartup.ini", "Disabled Startup Programs", $itemText, "NotFound")
        EndIf
        
        If $iniVal <> "NotFound" AND $iniVal = 0 Then
        
            ;ControlSend($configWin, "", $listview, "{SPACE}")
            ;$test = _GUICtrlListView_SetItemState($listview, $i, 1, $GUI_UNCHECKED)
            ;$test = _GUICtrlListView_SetItemChecked($listview, $i, False)
            ;$test = _GUICtrlListView_SetItemChecked($listview, $i, "False")
            
            ControlListView($configWin, "", $listview, "SelectClear")
            ControlListView($configWin, "", $listview, "Select", $i)
            ControlSend($configWin, "", $listview, "{SPACE}")
            ;_GUICtrlListView_SetItemSelected($List, $FocusItem)
            
            ;MsgBox(64, "uncheck test", $test)
        EndIf
            
        ;MsgBox(64, $i, $itemText & " - " & $iniVal)
    Next
EndFunc
Edited by KongMD

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I figured it out, finally. The helpfile is either wrong or misleading for _GUICtrlListView_SetItemChecked in that the $fCheck parameter's accepted values are 1 and 0, not True and False. Here is the correct syntax to uncheck a listview item:

$test = _GUICtrlListView_SetItemChecked($listview, $i, 0)

Thanks for your help, though, BrewManNH!

Edited by KongMD

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0