Jump to content

Treeview


fifi
 Share

Recommended Posts

Hi,

i am sorry but i can not find a way with treeview to get the handle of the mainitem, if a subitem of a mainitem is clicked.

For example:

Tree

----->Mainitem1

----------->Subitem11

----------->Subitem12

----->Mainitem2

----------->Subitem21

----------->Subitem22

...

For example:

The subitem12 is clicked (Mainitem1 must be expanded to see subitem12)

and i need to know the handle of Mainitem1.

I have seen that there a new things in Beta 54, but i do not understand the documentation how to use this.

Thankx for help

FIFI

Link to comment
Share on other sites

Hi,

i am sorry but i can not find a way with treeview to get the handle of the mainitem, if a subitem of a mainitem is clicked.

For example:

Tree

----->Mainitem1

----------->Subitem11

----------->Subitem12

----->Mainitem2

----------->Subitem21

----------->Subitem22

...

For example:

The subitem12 is clicked (Mainitem1 must be expanded to see subitem12)

and i need to know the handle of Mainitem1.

I have seen that there a new things in Beta 54, but i do not understand the documentation how to use this.

Thankx for help

FIFI

<{POST_SNAPBACK}>

From my point of view there is no way to retrieve the relation. You need to memorize what you did at the creation time and use the ControlId of subitem.

From my point of view .54 does add anything in this area.

Holger can confirm all this information in case I am wrong. :)

Link to comment
Share on other sites

Maybe like this:

#include <GUIConstants.au3>

Global $TV_FIRST            = 0x1100
Global $TVM_GETNEXTITEM        = $TV_FIRST + 10
Global $TVGN_PARENT            = 0x0003
Global $TVGN_CARET            = 0x0009

GUICreate("Test")
$tree        = GUICtrlCreateTreeView(10,10,200,200)

$item1        = GUICtrlCreateTreeViewItem("Mainitem1",$tree)
$subitem1    = GUICtrlCreateTreeViewItem("Subitem11",$item1)
$subitem2    = GUICtrlCreateTreeViewItem("Subitem12",$item1)
$item2        = GUICtrlCreateTreeViewItem("Mainitem2",$tree)
$subitem3    = GUICtrlCreateTreeViewItem("Subitem21",$item2)
$subitem4    = GUICtrlCreateTreeViewItem("Subitem22",$item2)

$button        = GUICtrlCreateButton("Check",50,220,70,20)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $button
            Msgbox(0,"Handle",GetItemHandle(GUICtrlRead($tree)))
    EndSelect    
WEnd

Exit

Func GetItemHandle($item)
    $hItem        = GUICtrlSendMsg($tree,$TVM_GETNEXTITEM,$TVGN_CARET,0)
    $hParent    = GUICtrlSendMsg($tree,$TVM_GETNEXTITEM,$TVGN_PARENT,$hItem)
    Return $hParent
EndFunc

Regards

Holger

P.S. maybe there are some UDF's in the new beta - I don't know at the moment...

Edited by Holger
Link to comment
Share on other sites

I suppose I can add that one as _GUICtrlTreeViewGetParentHandle, man that's a long function name.

Edit: or _GUICtrlTreeViewGetParentID ?

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

I suppose I can add that one as _GUICtrlTreeViewGetParentHandle, man that's a long function name.

Edit: or _GUICtrlTreeViewGetParentID ?

<{POST_SNAPBACK}>

Hi,

will you add this to the treeview UDF?

If yes, I think there should be better a UDF which delivers the value of the Control-ID.

FIFI

Link to comment
Share on other sites

Hi,

i am sorry but there is an error in the example at the Function Reference of _GUICtrlTreeViewGetParentHandle.

At the example the function call is named _GUICtrlTreeViewGetParentID, which does (at the moment?) not exist.

Again my question:

Is it possible to add a UDF that delivers the value of the Control-ID ($parentitem) of the parent item instead of the windows handle?

FIFI

Link to comment
Share on other sites

Hi,

i am sorry but there is an error in the example at the Function Reference of _GUICtrlTreeViewGetParentHandle.

At the example the function call is named _GUICtrlTreeViewGetParentID, which does (at the moment?) not exist.

Again my question:

Is it possible to add a UDF that delivers the value of the Control-ID ($parentitem) of the parent item instead of the windows handle?

FIFI

<{POST_SNAPBACK}>

Thanks, corrected my example, and sent.

I'll look into it when I get time.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Hi gafrost,

maybe i am to silly and do not see an easy way to solve my problem.

I am building a application where the user can edit the text of the items of the treeview. Everything works fine with that. But to catch logical errors of the entered text by the user i have to read the text of the mainitem above the edited subitem.

Little bit confusing, so i try to show my problem you with your example of the new beta:

___________________________________________________________________

#include <GUIConstants.au3>

#include <GuiTreeView.au3>

opt ("MustDeclareVars", 1)

Dim $tree, $item1, $subitem1, $subitem2, $item2, $subitem3, $subitem4, $button, $msg, $Status

GUICreate("Test", 392, 254)

$tree = GUICtrlCreateTreeView(10, 10, 200, 200)

$item1 = GUICtrlCreateTreeViewItem("Mainitem1", $tree)

$subitem1 = GUICtrlCreateTreeViewItem("Subitem11", $item1)

$subitem2 = GUICtrlCreateTreeViewItem("Subitem12", $item1)

$item2 = GUICtrlCreateTreeViewItem("Mainitem2", $tree)

$subitem3 = GUICtrlCreateTreeViewItem("Subitem21", $item2)

$subitem4 = GUICtrlCreateTreeViewItem("Subitem22", $item2)

$button = GUICtrlCreateButton("Check", 220, 100, 70, 20)

$Status = GUICtrlCreateLabel("", 0, 234, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $button

GUICtrlSetData($Status, "Parent Handle: " & _GUICtrlTreeViewGetParentHandle ($tree))

EndSelect

WEnd

Exit

__________________________________________________________________

So at runtime in the statusline is showed for example "1318728" for the handle of Mainitem2 if i click subitem 21.

Now i want to read the text of mainitem2. How do i get from this returned handle back to the Control-ID which is stored at creating of the item in the variable $item2 ($item2 = GUICtrlCreateTreeViewItem("Mainitem2", $tree)) with the value 7.

In my complex application i use a array for managing the control-ID's. So i will not work with the windowshandle. For me it would be better to return the control-id (in my example 7).

Does this help to understand my question?

Thanks

FIFI

Link to comment
Share on other sites

I'll submit the function you need tonight after work, but here it is so you can use it

#include <GUIConstants.au3>
#include <GuiTreeView.au3>
opt("MustDeclareVars", 1)

Dim $tree, $item1, $subitem1, $subitem2, $item2, $subitem3, $subitem4, $button, $msg, $Status, $parent
GUICreate("Test", 392, 254)
$tree = GUICtrlCreateTreeView(10, 10, 200, 200)
$item1 = GUICtrlCreateTreeViewItem("Mainitem1", $tree)
$subitem1 = GUICtrlCreateTreeViewItem("Subitem11", $item1)
$subitem2 = GUICtrlCreateTreeViewItem("Subitem12", $item1)
$item2 = GUICtrlCreateTreeViewItem("Mainitem2", $tree)
$subitem3 = GUICtrlCreateTreeViewItem("Subitem21", $item2)
$subitem4 = GUICtrlCreateTreeViewItem("Subitem22", $item2)
$button = GUICtrlCreateButton("Check", 220, 100, 70, 20)
$Status = GUICtrlCreateLabel("", 0, 234, 392, 20, BitOR($SS_SUNKEN, $SS_CENTER))

GUISetState()
While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $button
         $parent = GUICtrlRead(_GUICtrlTreeViewGetParentID ($tree), 1)
         GUICtrlSetData($Status, "Parent Text: " & $parent[0])
   EndSelect
WEnd
Exit

;===============================================================================
;
; Description:            _GUICtrlTreeViewGetParentID
; Parameter(s):        $h_treeview - controlID
; Requirement:            None
; Return Value(s):    Returns the parent control ID
; User CallTip:        _GUICtrlTreeViewGetParentID($h_treeview) Gets the parent control ID of item selected in Tree-View control (required: <GuiTreeView.au3>)
; Author(s):            Gary Frost (custompcs@charter.net)
; Note(s):                :
;
;===============================================================================
Func _GUICtrlTreeViewGetParentID($h_treeview)
   Dim $hParent, $hItem, $iParent
  ; get the handle to item selected
   $hItem = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
  ; get the handle to parent of item selected
   $hParent = GUICtrlSendMsg($h_treeview, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem)
  ; set parent to selected
   GUICtrlSendMsg($h_treeview, $TVM_SELECTITEM, $TVGN_CARET, $hParent)
  ; get the control id of parent
   $iParent = GUICtrlRead($h_treeview)
  ; set selected back to original selected
   GUICtrlSendMsg($h_treeview, $TVM_SELECTITEM, $TVGN_CARET, $hItem)
   Return $iParent
EndFunc  ;==>_GUICtrlTreeViewGetParentID

Gary

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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