Jump to content

_GUICtrlTreeView_GetSelection - problem


atzoref
 Share

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

#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

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

  • Moderators

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

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