Jump to content

Disable (grey) a Treeviewitem


Recommended Posts

How does one disable a treeviewitem??

My forum search left me empty handed.

I just want to disable the first item.

#include <GUIConstants.au3>
$Form1 = GUICreate("Disable Treeviewitem", 242, 245, 193, 126)
$TreeView1 = GUICtrlCreateTreeView(40, 24, 153, 129, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$WS_GROUP,$WS_TABSTOP,$WS_BORDER), 0)
$TreeView1_0 = GUICtrlCreateTreeViewItem("Item1", $TreeView1)
                GUICtrlCreateTreeViewItem("Item1_0", $TreeView1_0)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Item2", $TreeView1)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Item3", $TreeView1)
$Button1 = GUICtrlCreateButton("Enable/Disable Item1", 40, 168, 153, 33, 0)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Local $state = GuiCtrlRead($TreeView1_0)
            If    BitAnd($state,$GUI_DISABLE )= $GUI_DISABLE Then
                GUICtrlSetState($TreeView1_0,BitOr($state,$GUI_ENABLE))
            Else
                GUICtrlSetState($TreeView1_0,BitOr($state,$GUI_DISABLE))
            EndIf
    EndSwitch
WEnd
Link to comment
Share on other sites

Not sure it can be done as of yet, Holger still hasn't implimented the Tri-State Treeview items either.

Doh!

Link to comment
Share on other sites

You could do some workaround like this-

#include <GUIConstants.au3>
Opt("GUIonEventMode",1)
$Form1 = GUICreate("Disable Treeviewitem", 242, 245, 193, 126)
$TreeView1 = GUICtrlCreateTreeView(40, 24, 153, 129,0)
$TreeView1_0 = GUICtrlCreateTreeViewItem("Item1", $TreeView1)
GUICtrlSetOnEvent(-1,"MSH")
$item_0 = GUICtrlCreateTreeViewItem("Item1_0", $TreeView1_0)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Item2", $TreeView1)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Item3", $TreeView1)
$Button1 = GUICtrlCreateButton("Enable/Disable Item1", 40, 168, 153, 33, 0)
GUICtrlSetOnEvent(-1,"But")
GUISetOnEvent($GUI_EVENT_CLOSE,"BYE")
GUISetState(@SW_SHOW)
$IsDisabled=0
while 1
    Sleep(1000)
WEnd
func MSH()
    if $IsDisabled=0 then
        MsgBox(0,"","")
    EndIf
EndFunc
Func bye()
    Exit
EndFunc
func but()
    if $IsDisabled=0 then
        GUICtrlSetColor($TreeView1_0,0x999999)
        $IsDisabled=1
    Else
        GUICtrlSetColor($TreeView1_0,0x000000)
        $IsDisabled=0
    EndIf
EndFunc

It's in event mode btw

Link to comment
Share on other sites

You could do some workaround like this-

#include <GUIConstants.au3>
Opt("GUIonEventMode",1)
$Form1 = GUICreate("Disable Treeviewitem", 242, 245, 193, 126)
$TreeView1 = GUICtrlCreateTreeView(40, 24, 153, 129,0)
$TreeView1_0 = GUICtrlCreateTreeViewItem("Item1", $TreeView1)
GUICtrlSetOnEvent(-1,"MSH")
$item_0 = GUICtrlCreateTreeViewItem("Item1_0", $TreeView1_0)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Item2", $TreeView1)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Item3", $TreeView1)
$Button1 = GUICtrlCreateButton("Enable/Disable Item1", 40, 168, 153, 33, 0)
GUICtrlSetOnEvent(-1,"But")
GUISetOnEvent($GUI_EVENT_CLOSE,"BYE")
GUISetState(@SW_SHOW)
$IsDisabled=0
while 1
    Sleep(1000)
WEnd
func MSH()
    if $IsDisabled=0 then
        MsgBox(0,"","")
    EndIf
EndFunc
Func bye()
    Exit
EndFunc
func but()
    if $IsDisabled=0 then
        GUICtrlSetColor($TreeView1_0,0x999999)
        $IsDisabled=1
    Else
        GUICtrlSetColor($TreeView1_0,0x000000)
        $IsDisabled=0
    EndIf
EndFunc

It's in event mode btw

Thanks for the reply, but not exactly what I am looking for. I need the checkboxes too. However, Holger has made some progress on the Tri-State treeview. Please see here.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...