Jump to content

Selected Line in Listbox, to another Box.


Recommended Posts

-Hello this is my first topic. If this topic is in wrong place put it elsewhere, sorry.

When I have a few lines in a listbox, click one to select it, would it be possible
that I saw data in another window, e,g an edit box (or you suggest something better).
I used a small example, If more info is needed it will take a short while. I found a tree

to be a bit to small. Concept would be

-listbox-
Person a, (line 1)
Person b, (line 2)

------------------

Than what will be seen in a different box
(currently chose editbox) are  things like
age, playtime for both persons individual stats
and so line1 will show different info than line2: 

-edit box-

Age:
Playtime:
-----------------


Greetings Theolonghair, Ned

Link to comment
Share on other sites

  • Moderators

theolonghair,

Welcome to the AutoIt forum. :)

Perhaps this might give you some inspiration:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <GuiListBox.au3>

; Create array to hold edit ControlIDs
Global $aEdit[3]

; Create array to hold individual data
Global $aData[5][3] = [ _
    ["Person 0", 20, "2:30"], _
    ["Person 1", 21, "2:31"], _
    ["Person 2", 22, "2:32"], _
    ["Person 3", 23, "2:33"], _
    ["Person 4", 24, "2:34"]]
;     Name       Age  Time
    
; Pull names from array
$sData = ""
For $i = 0 To UBound($aData) - 1
    $sData &= "|" & $aData[$i][0]
Next

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 200, 220, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL, $LBS_MULTIPLESEL))
GUICtrlSetData($cList, $sData)

For $i = 1 To 2
    $aEdit[$i] = GUICtrlCreateEdit("", 250, (110 * $i) - 100, 240, 100, $ES_READONLY)
Next

$cClear = GUICtrlCreateButton("Clear", 10, 250, 80, 30)
$cRead = GUICtrlCreateButton("Read", 100, 250, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cRead
            ; Get selected items
            $aSel = _GUICtrlListBox_GetSelItems($cList)
            ; Check there are only 2
            If $aSel[0] = 2 Then
                ; For each selceted item
                For $i = 1 To 2
                    ; Get index
                    $iIndex = $aSel[$i]
                    ; Extract data from the array
                    $sData = "|" & $aData[$iIndex][0] & @CRLF & $aData[$iIndex][1] & @CRLF & $aData[$iIndex][2]
                    ; And add to edits
                    GUICtrlSetData($aEdit[$i], $sData)
                Next
            EndIf
            ; Clear selections
            ContinueCase
        Case $cClear
            ; Clear selections
            For $i = 0 To UBound($aData) - 1
                _GUICtrlListBox_SetSel($cList, $i, False)
            Next
    EndSwitch

WEnd
Please ask if you have any questions. :)

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

  • Moderators

theolonghair,

I am delighted that I did understand correctly and could produce something useful - I did have my doubts! :D

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

  • Moderators

theolonghair,

Do you mean just you want to have just the one edit which displays the selected person's info? :huh:

If so then just remove the loops and create/fill a single edit instead of the two that are there at present. :)

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

hmm, haha :) got no clue how to realise that. 
Im sorry to be such a burden.

I dont see where the loop starts/ends.
Though you are correct about what I asked.

Global $aData[5][3] = [ _
    ["Person 0", 20, "2:30"], _
    ["Person 1", 21, "2:31"], _
    ["Person 2", 22, "2:32"], _
    ["Person 3", 23, "2:33"], _
    ["Person 4", 24, "2:34"]]

and do I change the 3 in a 4 when I want more Lines in the editbox displayed?

Greetings From Netherlands.

Link to comment
Share on other sites

  • Moderators

theolonghair,

As it appears that you have little coding knowledge (and that is nto a problem as we all began at that point) you really should read the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) - this will help you to understand more about AutoIt syntax and code structure. You should also look at this excellent tutorial - you will find other tutorials in the Wiki (the link is at the top of the page). :)

But this is how you might modify the code I gave you above for a single selection: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <EditConstants.au3>
#include <GUIListBox.au3>
#include <Array.au3>

; Create array to hold edit ControlIDs
; Global $aEdit[3]  ; No longer needed  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; Create array to hold individual data
Global $aData[5][3] = [ _
    ["Person 0", 20, "2:30"], _
    ["Person 1", 21, "2:31"], _
    ["Person 2", 22, "2:32"], _
    ["Person 3", 23, "2:33"], _
    ["Person 4", 24, "2:34"]]
;     Name       Age  Time

; Pull names from array
$sData = ""
For $i = 0 To UBound($aData) - 1
    $sData &= "|" & $aData[$i][0]
Next

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$cList = GUICtrlCreateList("", 10, 10, 200, 220, BitOR($LBS_SORT, $WS_BORDER, $WS_VSCROLL)) ; $LBS_MULTIPLESEL no longer needed
GUICtrlSetData($cList, $sData)

; Remove first loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;For $i = 1 To 2
;    $aEdit[$i] = GUICtrlCreateEdit("", 250, (110 * $i) - 100, 240, 100, $ES_READONLY)
;Next

; Create single Edit control <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$cEdit = GUICtrlCreateEdit("", 250, 10, 240, 100, $ES_READONLY)

;$cClear = GUICtrlCreateButton("Clear", 10, 250, 80, 30) ; No longer needed <<<<<<<<<<<<<<<<<<<<<<<
$cRead = GUICtrlCreateButton("Read", 100, 250, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cRead
            ; And remove second loop <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            #cs
            ; Get selected items
            $aSel = _GUICtrlListBox_GetSelItems($cList)
            ; Check there are only 2
            If $aSel[0] = 2 Then
                ; For each selceted item
                For $i = 1 To 2
                    ; Get index
                    $iIndex = $aSel[$i]
                    ; Extract data from the array
                    $sData = "|" & $aData[$iIndex][0] & @CRLF & $aData[$iIndex][1] & @CRLF & $aData[$iIndex][2]
                    ; And add to edits
                    GUICtrlSetData($aEdit[$i], $sData)
                Next
            EndIf
            ; Clear selections
            ContinueCase
            #ce

            ; Check there is a selection
            $sListData = GUICtrlRead($cList)
            ; Check there was a selection
            If $sListData Then
                ; Get index
                $iIndex = _ArraySearch($aData, $sListData)
                If Not @error Then
                    ; Extract data from the array
                    $sData = $aData[$iIndex][0] & @CRLF & $aData[$iIndex][1] & @CRLF & $aData[$iIndex][2]
                    ; And add to edits
                    GUICtrlSetData($cEdit, $sData)
                EndIf
            EndIf
    EndSwitch

WEnd
As to adding elements to the array, I suggest you first read the Arrays tutorial in the Wiki and see if you can work it out yourself. You know where I am if you cannot. ;)

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

I will thank you <3 

-omg the little code beneath helped out so much.
I couldn't figure out why my 4th array didn't appear
in the box. And I added another "data index" thing
and it worked. haha feels good to do it myself.

state= *estatic* XD

; Extract data from the array
                    $sData = $aData[$iIndex][0] & @CRLF & $aData[$iIndex][1] & @CRLF & $aData[$iIndex][2]
                    ; And add to edits
Edited by theolonghair
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...