Jump to content

Update listbox data


rowish
 Share

Recommended Posts

I am kind of lost. I wanted to create this GUI with two list-boxes and an input. Depending of what item the user selects in the first list I would like that a certain set of data would be displayed on the second list. Also the input should concatenate the selected items. My code looks like this at this moment:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global $Hostname, $CountryCode, $StoreID, $StoreIDData

$MainForm = GUICreate("Hostname", 349, 184)
$HostnameInput = GUICtrlCreateInput("", 40, 24, 125, 21)
$CountryCodeList = GUICtrlCreateList("", 40, 56, 50, 87) ; 1st Combo
   GUICtrlSetData(-1, "BGR|ESP|FFM|GBR|ITA|POL|RUS", "FFM") ; Add alternatives and set default

$StoreIDList = GUICtrlCreateList("", 104, 56, 60, 87) ; 2nd Combo
   ; GUICtrlSetData(-1, $StoreIDData) ; Add alternatives and set default
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")


Func StoreData ()
   
$CountryCode = GUICtrlRead($CountryCodeList)
   Select
      Case $CountryCode = "BGR" 
         $StoreIDData = "10|11|15|16|18|21"
         GUICtrlSetData($StoreIDList, $StoreIDData)
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
      Case $CountryCode = "ESP" 
         $StoreIDData = "1|2|3|5|9|12|14|18|22|23"
         GUICtrlSetData($StoreIDList, $StoreIDData)
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))        
      Case $CountryCode = "FFM" 
         $StoreIDData = "0"
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
      Case $CountryCode = "GBR" 
         $StoreIDData = "1|2|3|4|5|6|7|8|9|10|11|12"
         GUICtrlSetData($StoreIDList, $StoreIDData)
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))        
      Case $CountryCode = "ITA" 
         $StoreIDData = "10|11|12|13|14|15|16|17|18"
         GUICtrlSetData($StoreIDList, $StoreIDData)
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))        
      Case $CountryCode = "POL" 
         $StoreIDData = "1|2|5|7|9|10|11|12|14|15|18"
         GUICtrlSetData($StoreIDList, $StoreIDData)
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))        
      Case $CountryCode = "RUS" 
         $StoreIDData = "10|11|12|15|16|19|20|21|22|29|32"
         GUICtrlSetData($StoreIDList, $StoreIDData)
         GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))        
      EndSelect
EndFunc
      
While 1
   $Msg = GUIGetMsg()
   ;StoreData($CountryCode)
   Select
      Case $Msg = $GUI_EVENT_CLOSE
         Exit
      EndSelect
   Storedata()
WEnd

Apparently it doesn't work as I wanted since I don't think I am doing the loop the right way. Could anybody help me, please?

Thank you.

Edited by rowish
Link to comment
Share on other sites

  • Moderators

rowish,

What exactly do you want to appear in the input? The items selected in the CountryCode list or those in the StoreID list? :huh:

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

Hi,

Try this, it can be improved.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <Array.au3>
 
Global $sLastCountryCodeList = ""
 
Global $Hostname, $CountryCode, $StoreID, $StoreIDData
 
$MainForm = GUICreate("Hostname", 349, 184)
$HostnameInput = GUICtrlCreateInput("", 40, 24, 125, 21)
$CountryCodeList = GUICtrlCreateList("", 40, 56, 50, 87) ; 1st Combo
GUICtrlSetData(-1, "BGR|ESP|FFM|GBR|ITA|POL|RUS", "FFM") ; Add alternatives and set default
 
$StoreIDList = GUICtrlCreateList("", 104, 56, 60, 87, $LBS_EXTENDEDSEL) ; 2nd Combo
; GUICtrlSetData(-1, $StoreIDData) ; Add alternatives and set default
GUISetState(@SW_SHOW, $MainForm)
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
Func StoreData()
    $sCountryCodeList = GUICtrlRead($CountryCodeList)
    If $sCountryCodeList = $sLastCountryCodeList Then Return 0
 
    GUICtrlSetData($StoreIDList, "")
 
    Switch $sCountryCodeList
        Case "BGR"
            $StoreIDData = "10|11|15|16|18|21"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "ESP"
            $StoreIDData = "1|2|3|5|9|12|14|18|22|23"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "FFM"
            $StoreIDData = "0"
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "GBR"
            $StoreIDData = "1|2|3|4|5|6|7|8|9|10|11|12"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "ITA"
            $StoreIDData = "10|11|12|13|14|15|16|17|18"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "POL"
            $StoreIDData = "1|2|5|7|9|10|11|12|14|15|18"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "RUS"
            $StoreIDData = "10|11|12|15|16|19|20|21|22|29|32"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
    EndSwitch
 
    $sLastCountryCodeList = $sCountryCodeList
EndFunc   ;==>StoreData
 
Func WM_COMMAND($hWnd, $iMsg, $iParam, $lParam)
    Local $iIDFrom = 0, $iCode = 0
 
    $iIDFrom = BitAND($iParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iParam, 16) ; Hi Word
 
    Switch $iIDFrom
        Case $StoreIDList
            Switch $iCode
                Case $LBN_SELCHANGE
                    Local $aData = _GUICtrlListBox_GetSelItemsText($StoreIDList)
 
                    GUICtrlSetData($HostnameInput, _ArrayToString($aData, ", ", 1))
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 
    StoreData()
    Sleep(10)
WEnd
Link to comment
Share on other sites

rowish,

What exactly do you want to appear in the input? The items selected in the CountryCode list or those in the StoreID list? :huh:

M23

 

Hi Melba,

I wanted to concatenate the selected items in both lists and use the string further. However the main issue was updating the second list after changing selection in the first one. FireFox shared the solution below.

 

Hi,

Try this, it can be improved.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIListBox.au3>
#include <Array.au3>
 
Global $sLastCountryCodeList = ""
 
Global $Hostname, $CountryCode, $StoreID, $StoreIDData
 
$MainForm = GUICreate("Hostname", 349, 184)
$HostnameInput = GUICtrlCreateInput("", 40, 24, 125, 21)
$CountryCodeList = GUICtrlCreateList("", 40, 56, 50, 87) ; 1st Combo
GUICtrlSetData(-1, "BGR|ESP|FFM|GBR|ITA|POL|RUS", "FFM") ; Add alternatives and set default
 
$StoreIDList = GUICtrlCreateList("", 104, 56, 60, 87, $LBS_EXTENDEDSEL) ; 2nd Combo
; GUICtrlSetData(-1, $StoreIDData) ; Add alternatives and set default
GUISetState(@SW_SHOW, $MainForm)
 
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
 
Func StoreData()
    $sCountryCodeList = GUICtrlRead($CountryCodeList)
    If $sCountryCodeList = $sLastCountryCodeList Then Return 0
 
    GUICtrlSetData($StoreIDList, "")
 
    Switch $sCountryCodeList
        Case "BGR"
            $StoreIDData = "10|11|15|16|18|21"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "ESP"
            $StoreIDData = "1|2|3|5|9|12|14|18|22|23"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "FFM"
            $StoreIDData = "0"
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "GBR"
            $StoreIDData = "1|2|3|4|5|6|7|8|9|10|11|12"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "ITA"
            $StoreIDData = "10|11|12|13|14|15|16|17|18"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "POL"
            $StoreIDData = "1|2|5|7|9|10|11|12|14|15|18"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
        Case "RUS"
            $StoreIDData = "10|11|12|15|16|19|20|21|22|29|32"
            GUICtrlSetData($StoreIDList, $StoreIDData)
            GUICtrlSetData($HostnameInput, $CountryCode & GUICtrlRead($StoreIDList))
    EndSwitch
 
    $sLastCountryCodeList = $sCountryCodeList
EndFunc   ;==>StoreData
 
Func WM_COMMAND($hWnd, $iMsg, $iParam, $lParam)
    Local $iIDFrom = 0, $iCode = 0
 
    $iIDFrom = BitAND($iParam, 0xFFFF) ; Low Word
    $iCode = BitShift($iParam, 16) ; Hi Word
 
    Switch $iIDFrom
        Case $StoreIDList
            Switch $iCode
                Case $LBN_SELCHANGE
                    Local $aData = _GUICtrlListBox_GetSelItemsText($StoreIDList)
 
                    GUICtrlSetData($HostnameInput, _ArrayToString($aData, ", ", 1))
            EndSwitch
    EndSwitch
 
    Return $GUI_RUNDEFMSG
EndFunc
 
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
 
    StoreData()
    Sleep(10)
WEnd

 

That's what I've been looking to in the first place. Thank you so much both of you.

Link to comment
Share on other sites

  • 1 month later...

I'm returning after a while, because after numerous attempts I couldn't make it work the way I wanted. I have to admit that the code in WM_COMMAND function is too advanced for my knowledge.

However, the $LBS_EXTENDEDSEL parameter of GUICtrlCreateList seems to limit the number of items displayed in the second listbox - there is no scrolling feature. If I eliminate it, the items are not displayed in the order they are written in the code. Also, I couldn't figure out how to add CountryCode selected item alongside StoreID in the input.

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