Jump to content

Removing multi selected item from a list


Recommended Posts

I've made some search but found nothing.

I've a list (GUICtrlCreateList) with some (around 400) items in it. User can multi select item from this list.

Clicking on a specific picture remove all selected item from the list.

- getting all selected item : no problem

- removing 1 selection item : no problem

- removing multi selection items : bug

Removing item change the others items id. So, i tried using _GUICtrlListBox_BeginUpdate and _GUICtrlListBox_EndUpdate, but it's the same bug.

Is there another way to remove many items from a list control at one time ?

Edited by spin0us
Link to comment
Share on other sites

What "items id"? Like the zero-based index? What if you delete from the end and go backwards?

For $iX = _GUICtrlListBox_GetCount To 0

ListDelete

Next

Also, some advice for the future. When asking a question, you should make a reproducer (short, working example). Not only will it help us understand more exactly what it is you are talking about, you will sometimes find the answer to the problem yourself when writing it, due to only the essential parts of the error being there (if you wrote a good reproducer).

Edit: meh

Edit2: FYI, when _GUICtrlListBox_BeginUpdate says "Prevents updating of the control" they mean it stops redrawing. Speeds up larger actions simply.

Edited by AdmiralAlkex
Link to comment
Share on other sites

Thanks for your replies.

I've already test the backwards solution but it does not work anymore.

I will try to use a temp array to store items, work on array and put array back in list.

It seems to be the only available fix :huh2:

Link to comment
Share on other sites

;#include <Array.au3>
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>


$hGUI = GUICreate("(UDF Created) List Box Create", 400, 296)
$hListBox = _GUICtrlListBox_Create($hGUI, "String upon creation", 2, 2, 396, 270, $LBS_EXTENDEDSEL)
GUISetState()

; Add files
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
_GUICtrlListBox_Dir($hListBox, @WindowsDir & "\win*.exe")
_GUICtrlListBox_AddFile($hListBox, @WindowsDir & "\Notepad.exe")
_GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES)
_GUICtrlListBox_Dir($hListBox, "", $DDL_DRIVES, False)
_GUICtrlListBox_EndUpdate($hListBox)

$bRemove = GUICtrlCreateButton("Remove", 10, 260)

; Loop until user exits
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bRemove
            $a_SelectedItems = _GUICtrlListBox_GetSelItems($hListBox)
            ;_ArrayDisplay($a_SelectedItems)
            For $i = $a_SelectedItems[0] To 1 Step -1
                _GUICtrlListBox_DeleteString($hListBox, $a_SelectedItems[$i])
            Next
    EndSwitch
WEnd

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