Jump to content

[SOLVED] Treeview expand parent but not childeren


nend
 Share

Recommended Posts

Hoi

Is it possible in a treeview to expand all parent but not the childeren?

If I use "_GUICtrlTreeView_Expand" than it will expand all childeren as well.

Thanks!

Edited by nend
Link to comment
Share on other sites

It will probably take a function with your own logic.  Here are the funcs I would use to accomplish this:
 

_GUICtrlTreeView_SetState ( $hWnd, $hItem [, $iState = 0 [, $bSetState = 0]] )
_GUICtrlTreeView_IsParent ( $hWnd, $hParent, $hItem )
_GUICtrlTreeView_Level ( $hWnd, $hItem )
_GUICtrlTreeView_GetNextSibling ( $hWnd, $hItem )

 

Edited by spudw2k
Link to comment
Share on other sites

45 minutes ago, spudw2k said:

It will probably take a function with your own logic.  Here are the funcs I would use to accomplish this:
 

_GUICtrlTreeView_SetState ( $hWnd, $hItem [, $iState = 0 [, $bSetState = 0]] )
_GUICtrlTreeView_IsParent ( $hWnd, $hParent, $hItem )
_GUICtrlTreeView_Level ( $hWnd, $hItem )
_GUICtrlTreeView_GetNextSibling ( $hWnd, $hItem )

 

Thank for your anwser but I don't have a clue how to implement this?

Link to comment
Share on other sites

Ok, I'll do what I can to help.  Can you explain in more detail the behavior you want?  Do you have a script/example with treeview in it to work with?

5 hours ago, nend said:

expand all parent but not the childeren?

What is the structure of the tree?  Is there a single root or are there multiple parents at the root.  
How about a picture?

Also, this command/func will allow you to expand a single item.
 

_SendMessage(GUICtrlGetHandle($idTreeView), $TVM_EXPAND, $TVE_EXPAND, $hItem, 0, "wparam", "handle")

 

Edited by spudw2k
Link to comment
Share on other sites

On 30-6-2016 at 6:15 PM, spudw2k said:

Ok, I'll do what I can to help.  Can you explain in more detail the behavior you want?  Do you have a script/example with treeview in it to work with?

What is the structure of the tree?  Is there a single root or are there multiple parents at the root.  
How about a picture?

Also, this command/func will allow you to expand a single item.
 

_SendMessage(GUICtrlGetHandle($idTreeView), $TVM_EXPAND, $TVE_EXPAND, $hItem, 0, "wparam", "handle")

 

It took some time but here I have a sample program.

I've tryd your line of code above (_sendmessage) but no luck.

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

Local $SP_array[11], $C_array[11]

$gui = GUICreate("Gui", 500, 465, -1, -1, -1);, $WS_EX_TOPMOST)
$gui_treeView = GUICtrlCreateTreeView(10, 10, 480, 280, BitOr($TVS_HASBUTTONS, $TVS_DISABLEDRAGDROP, $TVS_HASLINES, $TVS_HASLINES, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $TVS_LINESATROOT))

$C_head_item = GUICtrlCreateTreeViewItem("Parent 1", $gui_treeView)
$SP_head_item = GUICtrlCreateTreeViewItem("Parent 2", $gui_treeView)

Local $SP_child = GUICtrlCreateTreeViewItem("Child", $SP_head_item)
Local $C_child = GUICtrlCreateTreeViewItem("Child", $C_head_item)

For $i=0 To 10
    $SP_array[$i] = GUICtrlCreateTreeViewItem($i, $SP_child)
    $C_array[$i] = GUICtrlCreateTreeViewItem($i, $C_child)
Next

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    Sleep(20)
WEnd

I want it to expand the Parent but not futher,  See the screen shot below.

Knipsel.JPG

I Hoop you have a idea how to do that.

Edited by nend
Link to comment
Share on other sites

  • Moderators

nend,

Just loop through the top level items of the TreeView and send the message to each one found:

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

Local $SP_array[11], $C_array[11]

$gui = GUICreate("Gui", 500, 465, -1, -1, -1);, $WS_EX_TOPMOST)
$gui_treeView = GUICtrlCreateTreeView(10, 10, 480, 280, BitOr($TVS_HASBUTTONS, $TVS_DISABLEDRAGDROP, $TVS_HASLINES, $TVS_HASLINES, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $TVS_LINESATROOT))

$C_head_item = GUICtrlCreateTreeViewItem("Parent 1", $gui_treeView)
$SP_head_item = GUICtrlCreateTreeViewItem("Parent 2", $gui_treeView)

Local $SP_child = GUICtrlCreateTreeViewItem("Child", $SP_head_item)
Local $C_child = GUICtrlCreateTreeViewItem("Child", $C_head_item)

For $i=0 To 10
    $SP_array[$i] = GUICtrlCreateTreeViewItem($i, $SP_child)
    $C_array[$i] = GUICtrlCreateTreeViewItem($i, $C_child)
Next

GUISetState()

$hItem = _GUICtrlTreeView_GetFirstItem($gui_treeView)
Do
    _SendMessage(GUICtrlGetHandle($gui_treeView), $TVM_EXPAND, $TVE_EXPAND, $hItem, 0, "wparam", "handle")
    $hItem = _GUICtrlTreeView_GetNextSibling($gui_treeView, $hItem)
Until $hItem = 0


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

And note you do not need a Sleep in a GUIGetMsg loop - as explained in the help file, the function has an automatic pause incorporated so as not to hog the CPU.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

1 hour ago, Melba23 said:

nend,

Just loop through the top level items of the TreeView and send the message to each one found:

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

Local $SP_array[11], $C_array[11]

$gui = GUICreate("Gui", 500, 465, -1, -1, -1);, $WS_EX_TOPMOST)
$gui_treeView = GUICtrlCreateTreeView(10, 10, 480, 280, BitOr($TVS_HASBUTTONS, $TVS_DISABLEDRAGDROP, $TVS_HASLINES, $TVS_HASLINES, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES, $TVS_LINESATROOT))

$C_head_item = GUICtrlCreateTreeViewItem("Parent 1", $gui_treeView)
$SP_head_item = GUICtrlCreateTreeViewItem("Parent 2", $gui_treeView)

Local $SP_child = GUICtrlCreateTreeViewItem("Child", $SP_head_item)
Local $C_child = GUICtrlCreateTreeViewItem("Child", $C_head_item)

For $i=0 To 10
    $SP_array[$i] = GUICtrlCreateTreeViewItem($i, $SP_child)
    $C_array[$i] = GUICtrlCreateTreeViewItem($i, $C_child)
Next

GUISetState()

$hItem = _GUICtrlTreeView_GetFirstItem($gui_treeView)
Do
    _SendMessage(GUICtrlGetHandle($gui_treeView), $TVM_EXPAND, $TVE_EXPAND, $hItem, 0, "wparam", "handle")
    $hItem = _GUICtrlTreeView_GetNextSibling($gui_treeView, $hItem)
Until $hItem = 0


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

And note you do not need a Sleep in a GUIGetMsg loop - as explained in the help file, the function has an automatic pause incorporated so as not to hog the CPU.

M23

You make it look so simple ;-) Thanks for the help!

And the pause in a loop is something I didnt know that the software allready take care of that, every day I learn something new.

Link to comment
Share on other sites

  • Moderators

nend,

Quote

every day I learn something new

You are certainly not alone in that.....

But when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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