Jump to content

Send different data than whats is text field of tree item


kistoff
 Share

Recommended Posts

I would like a tree item to send different text than what is displayed in the tree item text field. I made this script below to try to figure it out, but I have not been able to after searching to forums. Can anyone give me a tip on how I could do this?

I would like the tree to show "item 1", but the data actually displayed in the MsgBox will be "new 1".

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>

$_1 = GUICreate("My GUI with treeview", 267, 257, 1081, 392)
$Tab1 = GUICtrlCreateTab(68, 0, 198, 256)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TreeView1 = GUICtrlCreateTreeView(72, 49, 189, 202, -1, $WS_EX_CLIENTEDGE)
$TreeView1_0 = GUICtrlCreateTreeViewItem("menu 1", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("item 1", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("item 2", $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem("menu 2", $TreeView1)
$TreeView1_4 = GUICtrlCreateTreeViewItem("item 3", $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem("item 4", $TreeView1_3)
$Button9a = GUICtrlCreateButton("Send", 180, 25, 70, 20, 0)
GUISetState(@SW_SHOW)

$item1 = "new 1"
$item2 = "new 2"
$item3 = "new 3"
$item4 = "new 4"

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
    If $Msg = $Button9a Then Send_Tree()
    WEnd
    
Func Send_Tree()
    $item = GUICtrlRead($treeview1)
        If $item = 0 Then
            MsgBox(64, "Error", "No item currently selected")
            Else
    $text = GUICtrlRead($item, 1)
        If $text == "" Then
            MsgBox(16, "Error", "Error while retrieving infos about item")
        Else
            MsgBox(64, "TreeView Demo", "Current item selected is: " & $text)
        EndIf
    EndIf
EndFunc
Link to comment
Share on other sites

After sleeping I was able to make some progress, but the code displays all the $new variables one after another rather then just displaying one at a time. I would like it to only display one rather then go through all the new variables.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>

Global $C[6], $new[6]

$C[0] = "menu 1"
$C[1] = "item 1"
$C[2] = "item 2"
$C[3] = "menu 2"
$C[4] = "item 3"
$C[5] = "item 4"

$new[0] = "new 1"
$new[1] = "new 2"
$new[2] = "new 3"
$new[3] = "new 4"
$new[4] = "new 5"
$new[5] = "new 6"

$_1 = GUICreate("My GUI with treeview", 267, 257, 1081, 392)
$Tab1 = GUICtrlCreateTab(68, 0, 198, 256)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TreeView1 = GUICtrlCreateTreeView(72, 49, 189, 202, -1, $WS_EX_CLIENTEDGE)
$TreeView1_0 = GUICtrlCreateTreeViewItem($C[0], $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem($C[1], $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem($C[2], $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem($C[3], $TreeView1)
$TreeView1_4 = GUICtrlCreateTreeViewItem($C[4], $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem($C[5], $TreeView1_3)
$Button9a = GUICtrlCreateButton("Send", 180, 25, 70, 20, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
    If $Msg = $Button9a Then Send_Tree()
    WEnd
    
Func Send_Tree()
    GUICtrlRead($TreeView1, 1)
    For $i = 0 To 5
    MsgBox(64, "TreeView Demo", "Current item selected is: " & $new[$i])
    Next
EndFunc
Link to comment
Share on other sites

  • Moderators

kistoff,

Have a look at this:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $aList[6][2]

$aList[0][0] = "menu 1"
$aList[1][0] = "item 1"
$aList[2][0] = "item 2"
$aList[3][0] = "menu 2"
$aList[4][0] = "item 3"
$aList[5][0] = "item 4"

$aList[0][1] = "new 1"
$aList[1][1] = "new 2"
$aList[2][1] = "new 3"
$aList[3][1] = "new 4"
$aList[4][1] = "new 5"
$aList[5][1] = "new 6"

$_1 = GUICreate("My GUI with treeview", 267, 257, 1081, 392)
$Tab1 = GUICtrlCreateTab(68, 0, 198, 256)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TreeView1 = GUICtrlCreateTreeView(72, 49, 189, 202, -1, $WS_EX_CLIENTEDGE)
$TreeView1_0 = GUICtrlCreateTreeViewItem($aList[0][0], $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem($aList[1][0], $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem($aList[2][0], $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem($aList[3][0], $TreeView1)
$TreeView1_4 = GUICtrlCreateTreeViewItem($aList[4][0], $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem($aList[5][0], $TreeView1_3)
$Button9a = GUICtrlCreateButton("Send", 180, 25, 70, 20, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
    If $Msg = $Button9a Then Send_Tree()
WEnd
    
Func Send_Tree()
    $iIndex = _ArraySearch($aList, GUICtrlRead($TreeView1, 1))
    $sText = $aList[$iIndex][1]
    MsgBox(64, "TreeView Demo", "Current item selected is: " & $sText)
EndFunc

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

Ok, so I ran into a problem with the way the code works that Melba23 provided. I made a rather large tree and some of the names from $aList[x][0] are the same further down the list, which causes it to display only the first item = "" rather then what is in the second list. I made an example of what I mean below. If you click on the last item $aList[5][0] = (BLDG 31) and hit send it does not display not31, it displays what $aList[1][0] had set.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $aList[6][2]

$aList[0][0] = "Item 1"
$aList[1][0] = "BLDG 31"
$aList[2][0] = "item 3"
$aList[3][0] = "item 4"
$aList[4][0] = "item 5"
$aList[5][0] = "BLDG 31"

$aList[0][1] = "new 1"
$aList[1][1] = "new 2"
$aList[2][1] = "BLDG 31"
$aList[3][1] = "new 4"
$aList[4][1] = "new 5"
$aList[5][1] = "not31"

$_1 = GUICreate("My GUI with treeview", 267, 257)
$Tab1 = GUICtrlCreateTab(68, 0, 198, 256)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TreeView1 = GUICtrlCreateTreeView(72, 49, 189, 202, -1, $WS_EX_CLIENTEDGE)
$TreeView1_0 = GUICtrlCreateTreeViewItem($aList[0][0], $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem($aList[1][0], $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem($aList[2][0], $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem($aList[3][0], $TreeView1)
$TreeView1_4 = GUICtrlCreateTreeViewItem($aList[4][0], $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem($aList[5][0], $TreeView1_3)
$Button9a = GUICtrlCreateButton("Send", 180, 25, 70, 20, 0)
GUISetState(@SW_SHOW)

#cs
While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
        If $Msg = $Button9a Then Send_Ticket1()
WEnd

Func Send_Ticket1()
    GUICtrlRead($TreeView1)
    For $b = 0 to 5
    MsgBox(0, "", $Alist[$b][1])
    Next
EndFunc
#ce

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
    If $Msg = $Button9a Then Send_Tree()
WEnd
    
Func Send_Tree()
    $iIndex = _ArraySearch($aList, GUICtrlRead($TreeView1, 1))
    $sText = $aList[$iIndex][1]
    MsgBox(64, "TreeView Demo", "Current item selected is: " & $sText)
EndFuncoÝ÷ زØ^ØbH§Ê&zØb¥¢x-ébë(}·¥£î¶+kzÛ«Æ¥Ø^Ó~.+-ÇX­zk(æµêÚaz¶®¶­sb6æ6ÇVFRfÇC´uT6öç7FçG4WæS2fwC°¢6æ6ÇVFRfÇCµ7FF46öç7FçG2æS2fwC°¢6æ6ÇVFRfÇCµF$6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇCµG&VUfWt6öç7FçG2æS2fwC°¢6æ6ÇVFRfÇCµvæF÷w46öç7FçG2æS2fwC°¢6æ6ÇVFRfÇC´'&æS2fwC° ¤vÆö&Âb33c¶Æ7E³eÕ³%Ð ¢b33c¶Æ7E³Õ³ÒÒgV÷C´FVÒgV÷C°¢b33c¶Æ7E³Õ³ÒÒgV÷C´$ÄDr3gV÷C°¢b33c¶Æ7E³%Õ³ÒÒgV÷C¶FVÒ2gV÷C°¢b33c¶Æ7E³5Õ³ÒÒgV÷C¶FVÒBgV÷C°¢b33c¶Æ7E³EÕ³ÒÒgV÷C¶FVÒRgV÷C°¢b33c¶Æ7E³UÕ³ÒÒgV÷C´$ÄDr3gV÷C° ¢b33c¶Æ7E³Õ³ÒÒgV÷C¶æWrgV÷C°¢b33c¶Æ7E³Õ³ÒÒgV÷C¶æWr"gV÷C°¢b33c¶Æ7E³%Õ³ÒÒgV÷C´$ÄDr3gV÷C°¢b33c¶Æ7E³5Õ³ÒÒgV÷C¶æWrBgV÷C°¢b33c¶Æ7E³EÕ³ÒÒgV÷C¶æWrRgV÷C°¢b33c¶Æ7E³UÕ³ÒÒgV÷C¶æ÷C3gV÷C° ¢b33cµóÒuT7&VFRgV÷C´×uTvFG&VWfWrgV÷C²Â#crÂ#Sr¢b33cµF#ÒuT7G&Ä7&VFUF"cÂÂÂ#Sb¤uT7G&Å6WE&W6¦ærÓÂb33c´uTôDô4µtED²b33c´uTôDô4´TtB¢b33cµF%6VWCÒuT7G&Ä7&VFUF$FVÒgV÷CµF%6VWCgV÷C²¢b33cµG&VUfWsÒuT7G&Ä7&VFUG&VUfWrs"ÂCÂÂ#"ÂÓÂb33cµu5ôUô4ÄTåDTDtR¢b33cµG&VUfWsóÒuT7G&Ä7&VFUG&VUfWtFVÒb33c¶Æ7E³Õ³ÒÂb33cµG&VUfWs¢b33cµG&VUfWsóÒuT7G&Ä7&VFUG&VUfWtFVÒb33c¶Æ7E³Õ³ÒÂb33cµG&VUfWsó¢b33cµG&VUfWsó"ÒuT7G&Ä7&VFUG&VUfWtFVÒb33c¶Æ7E³%Õ³ÒÂb33cµG&VUfWsó¢b33cµG&VUfWsó2ÒuT7G&Ä7&VFUG&VUfWtFVÒb33c¶Æ7E³5Õ³ÒÂb33cµG&VUfWs¢b33cµG&VUfWsóBÒuT7G&Ä7&VFUG&VUfWtFVÒb33c¶Æ7E³EÕ³ÒÂb33cµG&VUfWsó2¢b33cµG&VUfWsóRÒuT7G&Ä7&VFUG&VUfWtFVÒb33c¶Æ7E³UÕ³ÒÂb33cµG&VUfWsó2¢b33c´'WGFöãÒuT7G&Ä7&VFT'WGFöâgV÷Cµ6VæBgV÷C²ÂÂ#RÂsÂ#¤uT6WE7FFR5uõ4õr ¥vÆR b33c´×6rÒuTvWD×6r bb33c´×6rÒb33c´uTôUdTåEô4Äõ4RFVâW@ bb33c´×6rÒb33c´'WGFöãFVâ6VæEõG&VR¥tVæ@ ¤gVæ26VæEõG&VR uT7G&Å&VBb33cµG&VUfWs f÷"b33c¶"ÒFòP ×6t&÷cBÂgV÷CµG&VUfWrFVÖògV÷C²ÂgV÷C´7W'&VçBFVÒ6VÆV7FVB3¢gV÷C²fײb33c´Æ7E²b33c¶%Õ³Ò æW@¤VæDgVæ
Link to comment
Share on other sites

  • Moderators

kistoff,

It is not surprising that you get the wrong answer - _ArraySearch will only return the FIRST element that matches the search value. You have 2 elements of the array that match:

$aList[0][0] = "Item 1"

$aList[1][0] = "BLDG 31" <<<<<<<<<<<<<

$aList[2][0] = "item 3"

$aList[3][0] = "item 4"

$aList[4][0] = "item 5"

$aList[5][0] = "BLDG 31" <<<<<<<<<<<<<

So it is quite normal that the function returns the first.

If you want repeated elements, the whole concept of the script needs to be rethought!

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

Thanks for the help Melba23, I didn't think having the tree send/display something other then what is in the viewable text field would be such a challenge. A tree would be ideal for what I need, but I could probably chop my tree or try something else all together.

Link to comment
Share on other sites

I found a rather simple solution that doesn't really effect my tree that much. I just put an extra number at the end of each duplicate name in my tree to avoid it finding and returning the first element in the array. Not really sure why I didn't think of this sooner, but thanks for the help Melba23!

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $aList[6][2]

$aList[0][0] = "Item 1"
$aList[1][0] = "BLDG 31"
$aList[2][0] = "item 3"
$aList[3][0] = "item 4"
$aList[4][0] = "item 5"
$aList[5][0] = "BLDG 31 [1]"

$aList[0][1] = "new 1"
$aList[1][1] = "new 2"
$aList[2][1] = "BLDG 31"
$aList[3][1] = "new 4"
$aList[4][1] = "new 5"
$aList[5][1] = "not31"

$_1 = GUICreate("My GUI with treeview", 267, 257)
$Tab1 = GUICtrlCreateTab(68, 0, 198, 256)
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$TreeView1 = GUICtrlCreateTreeView(72, 49, 189, 202, -1, $WS_EX_CLIENTEDGE)
$TreeView1_0 = GUICtrlCreateTreeViewItem($aList[0][0], $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem($aList[1][0], $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem($aList[2][0], $TreeView1_0)
$TreeView1_3 = GUICtrlCreateTreeViewItem($aList[3][0], $TreeView1)
$TreeView1_4 = GUICtrlCreateTreeViewItem($aList[4][0], $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem($aList[5][0], $TreeView1_3)
$Button9a = GUICtrlCreateButton("Send", 180, 25, 70, 20, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    If $Msg = $GUI_EVENT_CLOSE Then Exit
    If $Msg = $Button9a Then Send_Tree()
WEnd
   
Func Send_Tree()
    $iIndex = _ArraySearch($aList, GUICtrlRead($TreeView1, 1))
    $sText = $aList[$iIndex][1]
    MsgBox(64, "TreeView Demo", "Current item selected is: " & $sText)
EndFunc
Link to comment
Share on other sites

  • Moderators

kistoff,

Very nice. I really enjoy lateral thinking solutions like that!

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