DickG

_GUICtrlTreeView_GetChecked returns True when NOT checked

3 posts in this topic

I just noticed that when I tried to execute something when a treeview item is NOT checked, it didn't work.

The Help file says it returns True if the item is checked.

So I used: If _GUICtrlTreeView_GetChecked($Tree_P2800, $Tree_P2800_sel) = False because I want it to react only if the item is NOT checked.

But it would only work if I used True. Is the Help file wrong?

Share this post


Link to post
Share on other sites



Seems to work properly for me.

#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $aidItem[6], $hRandomItem, $idTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    GUICreate("TreeView Get Checked", 400, 300)
    Local $lblDebug = GUICtrlCreateLabel("No item selected", 2, 268, 368, 40)

    $idTreeView = GUICtrlCreateTreeView(2, 2, 396, 258, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState(@SW_SHOW)

    _GUICtrlTreeView_BeginUpdate($idTreeView)
    For $x = 0 To UBound($aidItem) - 1
        $aidItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x + 1), $idTreeView)
    Next
    _GUICtrlTreeView_EndUpdate($idTreeView)

    While (True)
        Local $state = True
        Switch (GUIGetMsg())
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aidItem[0]
                $state = _GUICtrlTreeView_GetChecked($idTreeView, $aidItem[0])
                GUICtrlSetData($lblDebug, "Item [01] was clicked | Checked: " & $state)
                If (Not $state) Then MsgBox("", "", "State was false, displaying msgbox")
            Case $aidItem[1]
                $state = _GUICtrlTreeView_GetChecked($idTreeView, $aidItem[1])
                GUICtrlSetData($lblDebug, "Item [02] was clicked | Checked: " & $state)
                If (Not $state) Then MsgBox("", "", "State was false, displaying msgbox")
            Case $aidItem[2]
                $state = _GUICtrlTreeView_GetChecked($idTreeView, $aidItem[2])
                GUICtrlSetData($lblDebug, "Item [03] was clicked | Checked: " & $state)
                If (Not $state) Then MsgBox("", "", "State was false, displaying msgbox")
            Case $aidItem[3]
                $state = _GUICtrlTreeView_GetChecked($idTreeView, $aidItem[3])
                GUICtrlSetData($lblDebug, "Item [04] was clicked | Checked: " & $state)
                If (Not $state) Then MsgBox("", "", "State was false, displaying msgbox")
            Case $aidItem[4]
                $state = _GUICtrlTreeView_GetChecked($idTreeView, $aidItem[4])
                GUICtrlSetData($lblDebug, "Item [05] was clicked | Checked: " & $state)
                If (Not $state) Then MsgBox("", "", "State was false, displaying msgbox")
            Case $aidItem[5]
                $state = _GUICtrlTreeView_GetChecked($idTreeView, $aidItem[5])
                GUICtrlSetData($lblDebug, "Item [06] was clicked | Checked: " & $state)
                If (Not $state) Then MsgBox("", "", "State was false, displaying msgbox")
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

Interesting. Your code works correctly on my system too.

I suspect it's my logic. I'll have a closer look at it.

Thanks much for your help.

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