Jump to content

Getting the content of a list box as a string or array


 Share

Go to solution Solved by nullschritt,

Recommended Posts

Hello all, until recently I was using a listview to sort out a list of data, however I now feel it would look better to put the data in a listbox, rather than a list view. I found a function to convert listviews into an array but none to put a listbox in an array or string(that I could find)

Could anyone provide some help with this?

Link to comment
Share on other sites

I would assume that the steps are similar, just substituting _GUICtrlList_*  for the  equivalent _GUICtlrListView_* function.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Solution

I would assume that the steps are similar, just substituting _GUICtrlList_*  for the  equivalent _GUICtlrListView_* function.

The functions are not that simmilar, the function for listviews returns a 2d array of the data inside it (since the data can be in a grid, with rows and columns).

I made this, it seems to work.

func _guictrllistbox_getall($control)
                                $count = _GUICtrlListBox_GetCount($control)
                                $temp = ""
                                for $i=0 to $count-1
                                    $temp &= _GUICtrlListBox_GetText($control, $i)&"|"
                                Next
                                Return $temp
EndFunc
Link to comment
Share on other sites

  • 8 months later...

I know this post is a little bit old but I ran into the same issue and thought I'd share.  Rather than having to recycle my code, I wrote this. --Skampp

; #FUNCTION# ====================================================================================================================
; Name ..........: _ListBoxToArray
; Description ...: Creates a 1-dimensional 0-based array from a listbox
; Syntax ........: _ListBoxToArray($iListBox, $iListBoxNumber)
; Parameters ....: $iListBox            - Control ID of the ListBox Control
;                  $iListBoxNumber      - Instance Number of the ListBox Control
; Return values .: $iReturnName     - Array containing the items in the ListBox
; Author ........: Skampp
; Modified ......:
; Remarks .......: This may exist elsewhere but I could not find it.  Requires <GUIListBox.au3>
; Related .......: _GUICtrlListBox_GetCount, _GUICtrlListBox_GetText, ControlGetHandle
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _ListBoxToArray($iListBox, $iListBoxNumber)
    Local $iReturnName[100] ;maximum realistic number of items for a listbox
    $cC = 1 ;counter
    $iMax = _GUICtrlListBox_GetCount($iListBox) ;number of items in the listbox
    ReDim $iReturnName[$iMax + 1] ;resize the array
    Local $hListBoxHandle = ControlGetHandle($iTitle, "", "[CLASS:ListBox;INSTANCE:" & $iListBoxNumber & "]") ;get the control handle
    $iReturnName[0] = $iMax ;store the array size in [0]
    For $cC = 0 To $iMax - 1 ;start counter
        $iReturnName[$cC + 1] = _GUICtrlListBox_GetText($hListBoxHandle, $cC)   ;populate array from listbox
    Next
    Return $iReturnName ;return the array
EndFunc   ;==>_ListBoxToArray
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...