Jump to content

TreeView Searching / Menu item prob


Recommended Posts

Hi i wanted to ask some questions about the problem of the treeview i have.

Here's the example i have.

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <guitreeview.au3>

$Form1 = GUICreate("Form1", 528, 298, 264, 115)
$TreeView1 = GUICtrlCreateTreeView(8, 8, 505, 193)
$Input1 = GUICtrlCreateInput("Type the name to search", 184, 216, 153, 21)
$Button1 = GUICtrlCreateButton("Search", 184, 248, 155, 25)
$contex = GUICtrlCreateContextMenu($TreeView1)
$add = GUICtrlCreateMenuItem("Add",$contex)
GUISetState(@SW_SHOW)

_GUICtrlTreeView_BeginUpdate($TreeView1)
$first = _GUICtrlTreeView_Add($TreeView1,0,"First")
for $i = 1 to 15
    _GUICtrlTreeView_AddChild($TreeView1,$first,$i)
Next
$second = _GUICtrlTreeView_Add($TreeView1,0,"Second")
for $i = 16 to 30
    _GUICtrlTreeView_AddChild($TreeView1,$second,$i)
Next
_GUICtrlTreeView_EndUpdate($TreeView1)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1
            $searchitem = _GUICtrlTreeView_FindItem($TreeView1,GUICtrlRead($Input1),True)
            _GUICtrlTreeView_SelectItem($TreeView1,$searchitem)
            _GUICtrlTreeView_EnsureVisible($TreeView1,$searchitem)
        case $add
            $gettext = _GUICtrlTreeView_GetText($TreeView1,_GUICtrlTreeView_GetSelection($TreeView1))
            GUICtrlSetData($Input1,$gettext)
    EndSwitch
WEnd


First when i right click on an item to add it to the input it back to the first one ... i know that i must first click on the item then right click but is there a way to just right click on it and get the right item ?
Second i don't want to use findnext just when i click on search two times it searches for the second item is that possible ?
thanks

Edited by LerN
Link to comment
Share on other sites

  • Moderators

@LerN you have been around long enough to know that you need to give meaningful titles to your posts. Everyone is looking for help, generally because they have a problem...

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Just now, JLogan3o13 said:

@LerN you have been around long enough to know that you need to give meaningful titles to your posts. Everyone is looking for help, generally because they have a problem...

Yea i noticed that after i opened the thread ... can i edit it ?

Link to comment
Share on other sites

There's probably a better way but this is my attempt

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <guitreeview.au3>

Opt('GUIOnEventMode', 1)

GUICreate("Form1", 528, 298)
GUISetOnEvent($GUI_EVENT_CLOSE, 'ProgramClose')

Global $h_Next = 0
Global $i_TreeViewID = GUICtrlCreateTreeView(8, 8, 505, 193)
Global $i_SearchInputID = GUICtrlCreateInput("Type the name to search", 184, 216, 153, 21)
GUICtrlCreateButton("Search", 184, 248, 155, 25)
GUICtrlSetOnEvent(-1, 'FindSelectedItem')

LoadTreeView() ; load the treeview

GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func FindSelectedItem()
    Local $h_SearchItem = _GUICtrlTreeView_FindItem($i_TreeViewID, GUICtrlRead($i_SearchInputID), True, $h_Next)
    _GUICtrlTreeView_SelectItem($i_TreeViewID, $h_SearchItem)
    _GUICtrlTreeView_EnsureVisible($i_TreeViewID, $h_SearchItem)

    If Not $h_SearchItem Then
        $h_Next = 0
        MsgBox(0, 'That''s All Folks', 'All search strings found')
    Else
        $h_Next = _GUICtrlTreeView_GetNext($i_TreeViewID, $h_SearchItem)
    EndIf

EndFunc   ;==>FindSelectedItem

Func LoadTreeView()
    _GUICtrlTreeView_BeginUpdate($i_TreeViewID)

    Local $i_ParentID = GUICtrlCreateTreeViewItem("First", $i_TreeViewID)

    For $i = 1 To 15
        GUICtrlCreateTreeViewItem($i, $i_ParentID)
        GUICtrlSetOnEvent(-1, 'UpdateSearchBox')
    Next

    $i_ParentID = GUICtrlCreateTreeViewItem("Second", $i_TreeViewID)

    For $i = 16 To 30
        GUICtrlCreateTreeViewItem($i, $i_ParentID)
        GUICtrlSetOnEvent(-1, 'UpdateSearchBox')
    Next

    _GUICtrlTreeView_EndUpdate($i_TreeViewID)
EndFunc   ;==>LoadTreeView

Func UpdateSearchBox()
    If Not $h_Next Then GUICtrlSetData($i_SearchInputID, _GUICtrlTreeView_GetText($i_TreeViewID, GUICtrlRead($i_TreeViewID)))
EndFunc   ;==>UpdateSearchBox

Func ProgramClose()
    Exit
EndFunc   ;==>ProgramClose

 

Edited by benners
Removed redundant code
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...