Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_GUICtrlTreeView_GetSelection - problem


  • Please log in to reply
18 replies to this topic

#1 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 02 February 2012 - 02:12 PM

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, 04 February 2012 - 02:31 PM.








#2 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 04 February 2012 - 02:31 PM

Someone have an idea?

#3 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,388 posts

Posted 04 February 2012 - 02:44 PM

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

#4 LarsJ

LarsJ

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 452 posts

Posted 04 February 2012 - 02:46 PM

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.

#5 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 04 February 2012 - 02:57 PM

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

#6 LarsJ

LarsJ

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 452 posts

Posted 04 February 2012 - 03:13 PM

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.

#7 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 04 February 2012 - 03:16 PM

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?

#8 LarsJ

LarsJ

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 452 posts

Posted 04 February 2012 - 03:19 PM

Can you post the code with the problems?



#9 LarsJ

LarsJ

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 452 posts

Posted 04 February 2012 - 03:34 PM

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.

#10 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 05 February 2012 - 06:59 AM

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, 05 February 2012 - 07:38 AM.


#11 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,388 posts

Posted 05 February 2012 - 08:11 AM

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.

#12 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 05 February 2012 - 08:38 AM

No,
I'm working on my Autoit Script

Edited by atzoref, 05 February 2012 - 08:38 AM.


#13 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,388 posts

Posted 05 February 2012 - 08:45 AM

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

AutoIt         
#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


#14 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 05 February 2012 - 09:09 AM

This example not answer my problem...

#15 LarsJ

LarsJ

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 452 posts

Posted 05 February 2012 - 09:27 AM

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

#16 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,388 posts

Posted 05 February 2012 - 09:29 AM

AutoIt         
#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


#17 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 08 February 2012 - 09:22 AM

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

#18 atzoref

atzoref

    Prodigy

  • Active Members
  • PipPipPip
  • 189 posts

Posted 12 February 2012 - 07:59 AM

?

#19 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,115 posts

Posted 12 February 2012 - 09:08 AM

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
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users