Jump to content

TreeView check box to select only item, feed children to next loop


Skysnake
 Share

Recommended Posts

Hi Everyone

I have a very sexy Treeview that creates a "phonebook" type listing

+Jones [an item]

---- Albert [a child]

+Webster

---- David

---- John

---- Peter

It uses these styles:

Local $iStyle = BitOr ( $TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGANDDROP, $TVS_SHOWALWAYS, $TVS_CHECKBOXES )

It is created with GUICtrlCreateTreeview() and uses 

_GUICtrlTreeView_Add()

and 

 _GUICtrlTreeView_AddChild()

I want checkboxes ONLY on the items (surnames above), not the children. And, preferably the user must be able to click (select) the line (child) for info, but that info must preferable point to the item, so when browsing and click "John" the checkbox for WEBSTER should get ticked and return the handle/control id for WEBSTER, which I can then use to manipulate the item (and children) further.

Issue #1

My first issue is to get the checkboxes away from the children.

Issue #2

The info from the children can probably gleaned from here:

Thx @Melba23 :)

 Thx, skysnake

 

 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

  • Moderators

Skysnake,

I went looking how to have checkboxes only on certain items of the TreeView when I was working on my ChooseFileFolder UDF and found that you needed to create a completely owner-drawn TreeView control, which was far too much trouble in my opinion. What I did as a workaround was to look at the level of the item within the TreeView and only allow checks to be placed in those items which were allowed to accept them. You can find a function to do this in the GuiTreeView UDF - as well as another function allowing you to determine the parent for a given child, which will allow you to link back to the family name when a child is selected.

The GuiTreeView UDF has lots of interesting functions - and the ChooseFileFolder UDF shows how to use quite a few of them if you wish to take a look.

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

Thank your for the reply.

Hmm, I was really hoping there was somehthing like a GuiCtrlTreeViewGetItemforSelectedChild() ;)

 

Idea now is to include the item inside the child line ( a nested value), then simply use extract that value from the selected child and select the relevant value. Will try to post a working script by Monday.

 

Thanks again.

Skysnake

 

Skysnake

Why is the snake in the sky?

Link to comment
Share on other sites

Some treeview items with checkboxes and some without: I'm pretty sure it can be done in the same way as it's done for listview items here. I'll leave the details to you guys.
 

Link to comment
Share on other sites

  • Moderators

LarsJ,

It is even easier than that - adjusting the commented-out line removes the checkboxes from either root or children:

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

Local $aItem[4]

Local $hGUI = GUICreate("Test", 500, 500)

$hTV = _GUICtrlTreeView_Create($hGUI, 10, 10, 450, 450, BitOR($WS_BORDER, $TVS_CHECKBOXES, $TVS_HASLINES, $TVS_HASBUTTONS, $TVS_LINESATROOT))

$hRoot = _GUICtrlTreeView_Add($hTV, 0, "Root")

For $i = 1 To 3
    $aItem[$i]= _GUICtrlTreeView_AddChild($hTV, $hRoot, "Child" & $i)
Next

_GUICtrlTreeView_Expand($hTV)

GUISetState()

; Remove checkboxes from children - must be after GUISetState
For $i = 1 to 3
    _GUICtrlTreeView_SetStateImageIndex($hTV, $aItem[$i], 0)
Next

; Remove checkbox from root
;_GUICtrlTreeView_SetStateImageIndex($hTV, $hRoot, 0)

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

Thanks for the prod to get it working.

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

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

×
×
  • Create New...