Jump to content

Reset ID start value for mapping GUICtrlListView items


Achilles
 Share

Recommended Posts

Is there a way to reset the return value of _GUICtrlListView_MapIndextoId... I have a listview where the items are constantly being cleared and put on again.. this results in large ID numbers.. where, since the list is being cleared, starting at 0 again would be preferred.

Here's an example, just hit reset a couple times.

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <Array.au3>

GUICreate("ListView Map ID To Index", 400, 400)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState()
$btn = GUICtrlCreateButton('Reset', 10, 350, 200, 25)

; Add column
_GUICtrlListView_AddColumn($hListView, "Items", 400)

; Add items
Global $itemArray[1]
For $i = 1 to 25
    $temp = _GUICtrlListView_AddItem($hListView, "Item " & $i)
    _ArrayAdd($itemArray, $temp)
Next

_ArrayDisplay($itemArray, 'Mapped IDs')

; Loop until user exits
While 1
    Switch GUIGetMsg()
        Case $btn
            ; Clear all
            _GUICtrlLIstView_DeleteAllItems($hListView)
            ReDIm $itemArray[1]
            $itemArray[0] = ''

            ;Add new items, map them too
            For $i = 1 to 25
                $temp = _GUICtrlListView_AddItem($hListView, "Item " & $i)
                _ArrayAdd($itemArray, $temp)
            Next

            _ArrayDisplay($itemArray, 'Mapped IDs')
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEND
Edited by Achilles
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

It's also increasing the ID because you are not actually deleting any listview items. Watch your example, the list grows each time you reset it. As Authenticity pointed out, using GUICtrlDelete() on a control that is not managed by AutoIt (such as those created with _GUICtrlListView_AddItem()) will fail.

Just change this line:

_GUICtrlLIstView_DeleteAllItems(GUICtrlGetHandle($hListView))
Edited by wraithdu
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...