Re: Need A Quick Fix
- Posted by irv Nov 07, 2019
- 1198 views
Icy_Viking said...
Well I was able to get it to delete one item at a time. However I must be doing something a little wrong since I can't get it to delete a selected item, or it crashes.
procedure Remove_Game(integer self, integer event, sequence parm) for i = 1 to length(Game_List) do getIndex(Game_List) deleteItem(Game_List,getItem(Game_List,i)) end for end procedure setHandler(Game_List_Remove,w32HClick,routine_id("Remove_Game"))
getIndex() returns the index number(s) of the item(s) selected. You have to save that, and then delete the item or items, one at a time. Whether the index is an integer or a sequence of integers, depends upon which control is being used and whether single or multi-select is being done.
procedure Remove_Game(integer self, integer event, sequence parm) object index = getIndex(Game_List) ? index -- put this here for a peek at what is being returned if atom(index) and index > 0 then -- an item was selected, so... deleteItem(Game_List,index) else -- multiple items were selected, so... for i = 1 to length(index) do -- process each item deleteItem(Game_List,index[i]) end for end if end procedure setHandler(Game_List_Remove,w32HClick,routine_id("Remove_Game"))
From the Win32 docs:
getIndex ( list ) Get the index of the selected item(s), or cursor position in an edit control. Returns: INTEGER: Index of selected item, or zero if no item is selected. Category: List Control For ListView and TreeView, this returns a sequence of all selected items. For MleEdit, EditText and RichEdit, this returns the cursor position. For List, this returns the index of the currently selected item.
If you are sure you will never select more than one item at a time, you can do away with the for...loop.