JohnBailey Posted November 6, 2007 Share Posted November 6, 2007 (edited) QUESTION:I hope the title alone is clear enough, but here goes.What is the difference between the the return of _GUICtrlListView_AddItem() and _GUICtrlListView_MapIndexToID()? (IF ANY)It looks the same to me#include <GuiListView.au3> #include <GUIConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 633, 455, 193, 125) $ListView1 = GUICtrlCreateListView("Column1", 20, 22, 589, 350) $Input1 = GUICtrlCreateInput("", 24, 411, 121, 21) $Label1 = GUICtrlCreateLabel("ID via return", 26, 392, 62, 17) $Input2 = GUICtrlCreateInput("", 474, 410, 121, 21) $Label2 = GUICtrlCreateLabel("ID via map", 476, 391, 55, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") For $_x = 0 To 1 Local $itemID_viaReturn = _GUICtrlListView_AddItem($ListView1 ,'example') Local $itemID_viaMap = _GUICtrlListView_MapIndexToID($ListView1 , $_x) Next GuiCtrlSetData($Input1,$itemID_viaReturn) GuiCtrlSetData($Input2,$itemID_viaMap) While 1 Sleep(100) WEnd Func Form1Close() Exit EndFuncANSWERThey both do not return the item ID as previously read from the manual.#428818APPLICATION#428825 Edited November 6, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 6, 2007 Share Posted November 6, 2007 As you add/delete/insert items in a ListView the index of an item will change, but it's ID will not. If the index and ID happen to be the same, it's just a coincidence and can't be relied on to stay that way. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
JohnBailey Posted November 6, 2007 Author Share Posted November 6, 2007 As you add/delete/insert items in a ListView the index of an item will change, but it's ID will not. If the index and ID happen to be the same, it's just a coincidence and can't be relied on to stay that way. I TOTALLY MISREAD THE MANUAL! haha wow! Oh, I just need to not ask questions today. I'm so far gone already.I read the manual as saying that _GUICtrlListView_AddItem() and _GUICtrlListView_MapIndexToID() were both returning the ID (and not the index)! However, when setting up a reply I was pulling the quotes from the manual and then SLAP myself - there it was my stupidity staring at me.This is an example of how good rest/sleep, mental peace, and food influence careful reading. Thanks for your kind reply and not a slap PsaltyDS._GUICtrlListView_AddItem()Return ValueSuccess: The index of the new item_GUICtrlListView_MapIndexToID()Return ValueSuccess: The ID of the item A decision is a powerful thing Link to comment Share on other sites More sharing options...
JohnBailey Posted November 6, 2007 Author Share Posted November 6, 2007 (edited) Application of thisexpandcollapse popup#include <GUIConstants.au3> #include <GuiListView.au3> Func _LVDC_loadRowEntries($lvID,$___Array2D,$___rowStart=0,$___rowEnd=-1,$___colStart=0,$___colEnd=-1,$__appendtoLV=True) If NOT IsArray($___Array2D) Then SetError(0) Return -1 EndIf Local $___boundRowEnd = UBound($___Array2D)-1 If $___rowEnd > UBound($___Array2D)-1 OR $___rowEnd = -1 Then $___rowEnd = $___boundRowEnd Local $___boundColEnd = UBound($___Array2D,2)-1 If $___colEnd > UBound($___Array2D,2)-1 OR $___colEnd = -1 Then $___colEnd = $___boundColEnd If NOT $__appendtoLV Then _GUICtrlListView_DeleteAllItems($lvID) EndIf Local $__returnArrayItemIDs[1] Local $_arrayRowPos = $___rowStart Local $__LVrowStart = 0 Local $__LVrowEnd = $___rowEnd If $__appendtoLV Then Local $__LVItemCount = _GUICtrlListView_GetItemCount ($lvID) If $__LVItemCount > 0 Then $__LVrowEnd = $___rowEnd + $__LVItemCount $__LVrowStart = $__LVItemCount EndIf EndIf For $_x = $__LVrowStart to $__LVrowEnd Local $_lvColPos = $___colStart For $_xx = 0 to $___colEnd If $_xx = 0 Then Local $__addItemIndex = _GUICtrlListView_AddItem($lvID,$___Array2D[$_arrayRowPos][$_lvColPos]) ElseIf $_xx = $___colEnd Then _GUICtrlListView_AddSubItem($lvID,$_x, $___Array2D[$_arrayRowPos][$_lvColPos],$_xx ) Else _GUICtrlListView_AddSubItem($lvID, $_x, $___Array2D[$_arrayRowPos][$_lvColPos],$_xx) EndIf $_lvColPos +=1 ReDim $__returnArrayItemIDs[UBound($__returnArrayItemIDs)+1] $__returnArrayItemIDs[UBound($__returnArrayItemIDs)-1] = _GUICtrlListView_MapIndexToID($lvID, $__addItemIndex) Next $_arrayRowPos+=1 Next $__returnArrayItemIDs[0] = UBound($__returnArrayItemIDs)-1;is the total of items added Return $__returnArrayItemIDs EndFunc Func _LV_putInGroup($lvID,$_itemIDsArray,$_groupID) If NOT IsArray($_itemIDsArray) Then Return -1 EndIf If $_itemIDsArray[0] <= 0 Then Return -1 EndIf For $_a = 1 To $_itemIDsArray[0] Local $_itemIndex = _GUICtrlListView_MapIDToIndex($lvID, $_itemIDsArray[$_a]) _GUICtrlListView_SetItemGroupID($lvID, $_itemIndex, $_groupID) Next EndFuncEDITAdded the other function for this application exampleEDITAdded error testing Edited November 6, 2007 by JohnBailey A decision is a powerful thing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now