Sign in to follow this  
Followers 0

_GUICtrlTreeView_GetSelection - problem

19 posts in this topic

Posted (edited)

Hi,

I have a strange situation:

When I set an item to be checked with:

_GUICtrlTreeView_SetChecked($TestsViewHandle, $CurrentItemHandle , True)

If the item is a parent : _GUICtrlTreeView_GetSelection return True Handle Value which is OK,

But the problem if the item is a child : _GUICtrlTreeView_GetSelection return Wrong Handle Value = 0x000000.

Although If I set a child with the mouse to be checked (not with the _GUICtrlTreeView_SetChecked function)

_GUICtrlTreeView_GetSelection return True Handle Value which is OK,

I hope you understand my problem.

Why is that?

Thanks,

Adi

Edited by atzoref

Share this post


Link to post
Share on other sites



Posted

Someone have an idea?

Share this post


Link to post
Share on other sites

Posted

Theres a difference between selected and checked. Better give _GUICtrlTreeView_GetChecked() a try.

Share this post


Link to post
Share on other sites

Posted

Are you sure you have selected the child item before the _GetSelection command. According to the help file _GetSelection will return 0 if no item is selected. When you click an item with the mouse the item will automatically be selected.

Share this post


Link to post
Share on other sites

Posted

LarsJ:

That is what I don't understand....

I'm doing the : (_GUICtrlTreeView_SetChecked) before (_GetSelection) when it is a parent it OK but when it is a child it doesn't get true output from (_GetSelection)

Like I wrote.

What is the different? it should works the save way between parent and child.

Kafu:

I will try to play with it, I hope it will still work by this method....

Share this post


Link to post
Share on other sites

Posted

Yes, but _setChecked does not set the selection. If _GetSelection returns 0 it's because the item is not selected. If _GetSelection works with the parent, it's because the parent has the selection.

Share this post


Link to post
Share on other sites

Posted

Yes, but _setChecked does not set the selection. If _GetSelection returns 0 it's because the item is not selected. If _GetSelection works with the parent, it's because the parent has the selection.

So how you can explain why (_setChecked) does set the Selcetion with parent item whereas child not? what is the different?

Share this post


Link to post
Share on other sites

Posted

Can you post the code with the problems?

Share this post


Link to post
Share on other sites

Posted

A quick answer. I don't think it's the _SetChecked command that gave the parent the selection. It must have got the selection in some other way.

Share this post


Link to post
Share on other sites

Posted (edited)

You are right, Set_checked not change the GetSelection

(it ihas been changed only if the mouse checked an item or even just press on the item without checking the item)

But I must use the GetSelection command, so what command can do this like the mouse press on an item?

Or another command which can return the handle of an item which Checked or Selected by a command (and not by a mouse)

I tried : SetSelected

but it didn't changed.

Edited by atzoref

Share this post


Link to post
Share on other sites

Posted

Are you trying to manipulate a none Autoit program? If so, try something like

ControlListView ( "title", "text", controlID, "Select", From [, To])

and follow the remarks

"Some commands may fail when using a 32-bit AutoIt process to read from a 64-bit process. Likewise commands may fail when using a 64-bit AutoIt process to read from a 32-bit process."

meaning that if the target program is x64 then also Autoit needs to run as x64 and vice versa.

Share this post


Link to post
Share on other sites

Posted (edited)

No,

I'm working on my Autoit Script

Edited by atzoref

Share this post


Link to post
Share on other sites

Posted

Here's an adjusted example from the help-file working for me.

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

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()

    Local $hItem[10], $hItem_child[10][11],$iRand, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    GUICreate("TreeView Set Selected", 400, 300)

    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState()

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 0 To 9
        $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x), $hTreeView)
        For $y = 1 To Random(2, 10, 1)
            $hItem_child[$x][$y] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem[$x])
        Next
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

    _GUICtrlTreeView_SetSelected($hTreeView, $hItem[1])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem_child[1][3])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem_child[1][5])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem[3])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem[5])

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Share this post


Link to post
Share on other sites

Posted

This example not answer my problem...

Share this post


Link to post
Share on other sites

Posted

With _GetSelected/_GetChecked (not _GetSelection) you can work through all the items to check if they are selected/checked.

Share this post


Link to post
Share on other sites

Posted

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

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

_Main()

Func _Main()

    Local $hItem[10], $hItem_child[10][11],$iRand, $hTreeView
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

    GUICreate("TreeView Set Selected", 400, 300)

    $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE)
    GUISetState()

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    For $x = 0 To 9
        $hItem[$x] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Item", $x), $hTreeView)
        For $y = 1 To 10
            $hItem_child[$x][$y] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] New Child", $y), $hItem[$x])
        Next
    Next
    _GUICtrlTreeView_EndUpdate($hTreeView)

    _GUICtrlTreeView_SetSelected($hTreeView, $hItem[1])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem_child[1][3])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem_child[1][5])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem[3])
    _GUICtrlTreeView_SetSelected($hTreeView, $hItem[5])

    For $x = 0 To 9
        Switch _GUICtrlTreeView_GetSelected($hTreeView,$hItem[$x])
            Case True
                ConsoleWrite("! " & $x & @crlf)
            Case Else
                ConsoleWrite($x & @crlf)
        EndSwitch
        For $y = 1 To 10
            Switch _GUICtrlTreeView_GetSelected($hTreeView,$hItem_child[$x][$y])
                Case True
                    ConsoleWrite("! " & $x & " " & $y & @crlf)
                Case Else
                    ConsoleWrite($x & " " & $y & @crlf)
            EndSwitch
        Next
    Next

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

Share this post


Link to post
Share on other sites

Posted

Before I try this example

I look in the Help File about (_GUICtrlTreeView_GetSelection(

In the example there, they do:

$iRand = Random(0, 9, 1)
    _GUICtrlTreeView_SelectItem($hTreeView, $hItem[$iRand])
    MsgBox(4160, "Information", "Selection? " & _GUICtrlTreeView_GetSelection($hTreeView))

I do the same thing in my tree,

But why (GetSelection) always shows 0x0000000 (and not the handle which set by SelectItem Function)?

Share this post


Link to post
Share on other sites

Posted

?

Share this post


Link to post
Share on other sites

Posted

atzoref,

You have been here long enough to know that posting 3 lines of code is not going to get you very far - particularly when those 3 lines work perfectly in the Help file example. Obviously the problem lies elsewhere in you code, so without seeing it we cannot offer you any help at all. ;)

Post a working script and we will take a look. :)

M23

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
Sign in to follow this  
Followers 0