Sign in to follow this  
Followers 0
Achilles

Reset ID start value for mapping GUICtrlListView items

3 posts in this topic

#1 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites



Look how the _GUICtrlListView_DeleteAllItems() function is defined. If you send it something other than a handle to a listview control, it'll just use GUICtrlDelete(). Otherwise it'll send the LVM_DELETEALLITEMS, which resets the value of the index and items count.

$hListView = GUICtrlGetHandle($hListView)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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
Sign in to follow this  
Followers 0