Jump to content

How to move multiselect data from one list to another


Gene
 Share

Recommended Posts

I have a GUI with two large list boxes. I've been trying to move items from one to the other and back again. THe code I have, works fine as long as I only select one item at a time. When I select multiple items it partially works. I have some temp variable code in it that shows the List Box content variables to contain the correct information, but the display is wrong. The temp var data is displayed on screen in a label and written to a log file. The pertinent code is below. The entire code is in an attached ZIP file. I would appreciate some pointers on this.

$DualListDlg = GUICreate($sTitle, 624, 446, 219, 120)
$Label5 = GUICtrlCreateLabel("Boiler Plate Items", 65, 2, 126, 16)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label6 = GUICtrlCreateLabel("Items Embedded in Script", 385, 1, 199, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$ListBox1 = GUICtrlCreateList("", 10, 22, 280, 230, BitOR($LBS_EXTENDEDSEL,$WS_HSCROLL,$WS_VSCROLL), $WS_EX_CLIENTEDGE)
$sListBox1 = "Item1|Item2|Item3|Item4|Item5"
GUICtrlSetData($ListBox1, $sListBox1)
$Move2Rgt = GUICtrlCreateButton("==>", 294, 45, 37, 31, $BS_DEFPUSHBUTTON)
$Move2Lft = GUICtrlCreateButton("<==", 294, 100, 38, 30)
;GUICtrlSetState(-1, $GUI_DISABLE)
$ListBox2 = GUICtrlCreateList("", 336, 22, 280, 230, BitOR($LBS_EXTENDEDSEL,$WS_HSCROLL,$WS_VSCROLL), $WS_EX_CLIENTEDGE)
$sListBox2 = "Item6|Item7"
GUICtrlSetData($ListBox2, $sListBox2)
$Button5 = GUICtrlCreateButton("&Next", 308, 414, 92, 31)
$Button6 = GUICtrlCreateButton("&Cancel", 416, 414, 93, 31)
$Button7 = GUICtrlCreateButton("&Help", 525, 414, 92, 31)
$Button1 = GUICtrlCreateButton("&Save Value", 8, 414, 92, 31, $BS_DEFPUSHBUTTON)
$Label1 = GUICtrlCreateLabel("Variable or Directive:", 10, 261, 151, 20)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")


$Input1 = GUICtrlCreateInput("Variable or Directive", 170, 260, 441, 24, -1, $WS_EX_CLIENTEDGE)
$Label2 = GUICtrlCreateLabel("Variable or Directive Value", 10, 287, 191, 20)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Edit1 = GUICtrlCreateEdit("", 10, 310, 605, 59, -1, $WS_EX_CLIENTEDGE)
GUICtrlSetData($Edit1, "Variable or Directive Value")
$Label3 = GUICtrlCreateLabel("Description:", 10, 377, 87, 20)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label4 = GUICtrlCreateLabel("Description", 100, 377, 514, 30, $SS_SUNKEN)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x180000)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        $s_hexKey = "1B"
        $v_dll = 'user32.dll'
        If _IsPressed($s_hexKey, $v_dll) Then
            Sleep(20)
        Else    
            _EndProgram()
        EndIf   


    Case $msg = $Move2Rgt
        _Move2Rgt($ListBox1, $ListBox2)

    Case $msg = $Move2Lft
        _Move2Lft($ListBox2, $ListBox1)
        


    Case $msg = "foo3"


    Case Else
    ;;;;;;;

    EndSelect
WEnd
_EndProgram()




Func _Move2Rgt($ListBox1, $ListBox2)
        $aiListBox1 = _GUICtrlListGetSelItems($ListBox1)
        $asListBox1 = _GUICtrlListGetSelItemsText($ListBox1)
        For $i = 1 to $aiListBox1[0]
        _Label1($aiListBox1[$i], $asListBox1[$i], $sListBox1, $sListBox2)
            If $aiListBox1[0] <> $LB_ERR Then
                $sTempVar = $sListBox2
                $sListBox2 = ""
                GUICtrlSetData($ListBox2, $sListBox2)
                $sListBox2 = $sTempVar & "|" & $asListBox1[$i]
                GUICtrlSetData($ListBox2, $sListBox2)
                _GUICtrlListDeleteItem($ListBox1, $aiListBox1[$i])
                If StringInStr($sListBox1, $asListBox1[$i]) Then
                    $sListBox1 = StringReplace($sListBox1, $asListBox1[$i], "")
                    $sListBox1 = StringReplace($sListBox1, "||", "|")
                    If StringLeft($sListBox1, 1) = "|"Then
                        $sListBox1 = StringTrimLeft($sListBox1, 1)
                    EndIf
                    If StringRight($sListBox1, 1) = "|"Then
                        $sListBox1 = StringTrimRight($sListBox1, 1)
                    EndIf
                EndIf   
        _Label1($aiListBox1[$i], $asListBox1[$i], $sListBox1, $sListBox2)
            Else
                
            EndIf   
        Next    
        $aiListBox1 = 0
        $asListBox1 = ""
EndFunc



Func _Move2Lft($ListBox2, $ListBox1)
        $aiListBox2 = _GUICtrlListGetSelItems($ListBox2)
        $asListBox2 = _GUICtrlListGetSelItemsText($ListBox2)
        For $i = 1 to $aiListBox2[0]
        _Label2($aiListBox2[$i], $asListBox2[$i], $sListBox2, $sListBox1)
            If $aiListBox2[0] <> $LB_ERR Then
                $sTempVar = $sListBox1
                $sListBox1 = ""
                GUICtrlSetData($ListBox1, $sListBox1)
                $sListBox1 = $sTempVar & "|" & $asListBox2[$i]
                GUICtrlSetData($ListBox1, $sListBox1)
                _GUICtrlListDeleteItem($ListBox2, $aiListBox2[$i])
                If StringInStr($sListBox2, $asListBox2[$i]) Then
                    $sListBox2 = StringReplace($sListBox2, $asListBox2[$i], "")
                    $sListBox2 = StringReplace($sListBox2, "||", "|")
                    If StringLeft($sListBox2, 1) = "|"Then
                        $sListBox2 = StringTrimLeft($sListBox2, 1)
                    EndIf
                    If StringRight($sListBox2, 1) = "|"Then
                        $sListBox2 = StringTrimRight($sListBox2, 1)
                    EndIf
                EndIf   
                    
        _Label2($aiListBox2[$i], $asListBox2[$i], $sListBox2, $sListBox1)
            Else
                
            EndIf   
        Next    
        $aiListBox2 = 0
        $asListBox2 = ""
EndFunc

Func _Label1($tVar1, $tVar2, $tVar3, $tVar4)
    GUICtrlSetData($Label1a, "")
    $Label1a = GUICtrlCreateLabel("$aiListBox1[$i] = {" & $tVar1 & "} $aSListBox1[$i] = {" & $tVar2 & "} , $sListBox1 = {" & $tVar3 & "}", 10, 239, 600, 20)
    FileWrite("Action.Log","Label1  Move2Rgt  $aiListBox1[$i] = {" & $tVar1 & "} $aSListBox1[$i] = {" & $tVar2 & "} , $sListBox1 = {" & $tVar3 & "} , $sListBox2 = {" & $tVar4 & "}" & @CRLF)
EndFunc


Func _Label2($tVar1, $tVar2, $tVar3, $tVar4)
    GUICtrlSetData($Label1a, "")
    $Label1a = GUICtrlCreateLabel("$aiListBox2[$i] = {" & $tVar1 & "} $aSListBox2[$i] = {" & $tVar2 & "} , $sListBox2 = {" & $tVar3 & "}", 10, 239, 600, 20)
    FileWrite("Action.Log","Label2  Move2Lft  $aiListBox2[$i] = {" & $tVar1 & "} $aSListBox2[$i] = {" & $tVar2 & "} , $sListBox2 = {" & $tVar3 & "} , $sListBox1 = {" & $tVar4 & "}" & @CRLF)
EndFunc

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

Link to comment
Share on other sites

I have a GUI with two large list boxes. I've been trying to move items from one to the other and back again. THe code I have, works fine as long as I only select one item at a time. When I select multiple items it partially works. I have some temp variable code in it that shows the List Box content variables to contain the correct information, but the display is wrong. The temp var data is displayed on screen in a label and written to a log file.

<snipped>

Func _Move2Rgt($ListBox1, $ListBox2)

        $aiListBox1 = _GUICtrlListGetSelItems($ListBox1)

        $asListBox1 = _GUICtrlListGetSelItemsText($ListBox1)

        For $i = 1 to $aiListBox1[0]

        _Label1($aiListBox1[$i], $asListBox1[$i], $sListBox1, $sListBox2)

            If $aiListBox1[0] <> $LB_ERR Then

                $sTempVar = $sListBox2

                $sListBox2 = ""

                GUICtrlSetData($ListBox2, $sListBox2)

                $sListBox2 = $sTempVar & "|" & $asListBox1[$i]

                GUICtrlSetData($ListBox2, $sListBox2)

                _GUICtrlListDeleteItem($ListBox1, $aiListBox1[$i])

                If StringInStr($sListBox1, $asListBox1[$i]) Then

                    $sListBox1 = StringReplace($sListBox1, $asListBox1[$i], "")

                    $sListBox1 = StringReplace($sListBox1, "||", "|")

                    If StringLeft($sListBox1, 1) = "|"Then

                        $sListBox1 = StringTrimLeft($sListBox1, 1)

                    EndIf

                    If StringRight($sListBox1, 1) = "|"Then

                        $sListBox1 = StringTrimRight($sListBox1, 1)

                    EndIf

                EndIf    

        _Label1($aiListBox1[$i], $asListBox1[$i], $sListBox1, $sListBox2)

            Else

                

            EndIf    

        Next    

        $aiListBox1 = 0

        $asListBox1 = ""

EndFunc

Func _Move2Lft($ListBox2, $ListBox1)

        $aiListBox2 = _GUICtrlListGetSelItems($ListBox2)

        $asListBox2 = _GUICtrlListGetSelItemsText($ListBox2)

        For $i = 1 to $aiListBox2[0]

        _Label2($aiListBox2[$i], $asListBox2[$i], $sListBox2, $sListBox1)

            If $aiListBox2[0] <> $LB_ERR Then

                $sTempVar = $sListBox1

                $sListBox1 = ""

                GUICtrlSetData($ListBox1, $sListBox1)

                $sListBox1 = $sTempVar & "|" & $asListBox2[$i]

                GUICtrlSetData($ListBox1, $sListBox1)

                _GUICtrlListDeleteItem($ListBox2, $aiListBox2[$i])

                If StringInStr($sListBox2, $asListBox2[$i]) Then

                    $sListBox2 = StringReplace($sListBox2, $asListBox2[$i], "")

                    $sListBox2 = StringReplace($sListBox2, "||", "|")

                    If StringLeft($sListBox2, 1) = "|"Then

                        $sListBox2 = StringTrimLeft($sListBox2, 1)

                    EndIf

                    If StringRight($sListBox2, 1) = "|"Then

                        $sListBox2 = StringTrimRight($sListBox2, 1)

                    EndIf

                EndIf    

                    

        _Label2($aiListBox2[$i], $asListBox2[$i], $sListBox2, $sListBox1)

            Else

                

            EndIf    

        Next    

        $aiListBox2 = 0

        $asListBox2 = ""

EndFunc

<snipped>

After more reading of GUIList.au3, the following works:

Func _Move2Rgt($ListBox1, $ListBox2)
    $iError = _GUICtrlListGetSelItems($ListBox1)
    If $iError <> $LB_ERR Then
        $aiListBox1 = _GUICtrlListGetSelItems($ListBox1)
        $asListBox1 = _GUICtrlListGetSelItemsText($ListBox1)
        For $i = $aiListBox1[0] to 1 Step -1
            _GUICtrlListAddItem($ListBox2, $asListBox1[$i])
            _GUICtrlListDeleteItem($ListBox1, $aiListBox1[$i])
        Next
    EndIf   
EndFunc



Func _Move2Lft($ListBox2, $ListBox1)
    $iError = _GUICtrlListGetSelItems($ListBox2)
    If $iError <> $LB_ERR Then
        $aiListBox2 = _GUICtrlListGetSelItems($ListBox2)
        $asListBox2 = _GUICtrlListGetSelItemsText($ListBox2)
        For $i = $aiListBox2[0] to 1 Step -1
            _GUICtrlListAddItem($ListBox1, $asListBox2[$i])
            _GUICtrlListDeleteItem($ListBox2, $aiListBox2[$i])
        Next
    EndIf   
EndFunc

I'm sure there is a more elegant way, I'd be delighted if someone pointed it out. B)

[font="Verdana"]Thanks for the response.Gene[/font]Yes, I know the punctuation is not right...

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