Jfish Posted December 31, 2008 Posted December 31, 2008 Hello all,The short problem:I am getting stuck reading a listview control with GuiCtrlRead() to get the selected item. I can get it to work on other scripts. I think the problem may be that I used _GUICtrlListView_AddArray to populate the list view.The longer problem: I am trying to do a simple modification on Smashly's posting from June 2006: http://www.autoitscript.com/forum/index.ph...st&p=475519 to better understand how to manipualte items on a listview. The code below works for everything but "$delete". I am trying to read the selected item on the listview and then delete it from the array, delete all listview items, and re-populate it with the new array (without the deleted item). My goal is to create a shuttlelist where items can be added from one list to another, removed, moved up, and moved down. Everything is working on this except the remove/delete piece. I am only guessing that the use of _GUICtrlListView_AddArray does not play well with GuiCtrlRead and so I am getting "0" for all values when I attempt to read a highlighted item.Any help would be greatly appreciated. #include <GuiConstantsEx.au3>#include <GuiListView.au3>#include <Array.au3>Global $LVIT[5][5]$LVIT[0][0]="A"$LVIT[1][0]="B"$LVIT[2][0]="C"$LVIT[3][0]="D"$LVIT[4][0]="E"dim $deleteItem;_ArrayDisplay($LVIT)$Gui = GUICreate("ListView 5 Simple items A-E", 800, 600)$LV = GUICtrlCreateListView("Scripts",2, 2, 796, 556)_GUICtrlListView_AddArray($LV, $LVIT)$Down = GUICtrlCreateButton("Move Selected Down", 10, 566, 150, 25)$Up = GUICtrlCreateButton("Move Selected Up", 170, 566, 150, 25)$Display = GUICtrlCreateButton("Display $LVIT Array", 330, 566, 150, 25)$delete = GUICtrlCreateButton("deleteItem", 490, 566, 100, 25)$addItem = GUICtrlCreateButton("AddItem", 600, 566, 150, 25)GUISetState(@SW_SHOW)While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $Down Local $Sel, $Lst $Sel = _GUICtrlListView_GetNextItem($LV) $Lst = _GUICtrlListView_GetItemCount($LV) - 1 If $Sel < $Lst And $Sel <> -1 Then Local $SelTxt, $NxtTxt $SelTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel) $NxtTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel + 1) For $i = 1 To $SelTxt[0] $LVIT[$Sel][$i -1] = $NxtTxt[$i] $LVIT[$Sel +1][$i -1] = $SelTxt[$i] _GUICtrlListView_SetItemText($LV, $Sel, $NxtTxt[$i], $i -1) _GUICtrlListView_SetItemText($LV, $Sel + 1, $SelTxt[$i], $i - 1) _GUICtrlListView_SetItemSelected($LV, $Sel + 1) Next EndIf Case $Up Local $Sel = _GUICtrlListView_GetNextItem($LV) If $Sel > 0 Then Local $SelTxt, $NxtTxt $SelTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel) $PrvTxt = _GUICtrlListView_GetItemTextArray($LV, $Sel - 1) For $i = 1 To $SelTxt[0] $LVIT[$Sel][$i -1] = $PrvTxt[$i] $LVIT[$Sel -1][$i -1] = $SelTxt[$i] _GUICtrlListView_SetItemText($LV, $Sel, $PrvTxt[$i], $i - 1) _GUICtrlListView_SetItemText($LV, $Sel - 1, $SelTxt[$i], $i - 1) _GUICtrlListView_SetItemSelected($LV, $Sel - 1) Next EndIf Case $addItem Local $upper = UBound($LVIT);measures size of current array local $upperPlus1 = $upper + 1;adds 1 to the size of the array ReDim $LVIT [$upperPlus1][$upperPlus1];expands the array + 1 $LVIT[$upper][0]="newdata";writes the new value to the expanded slot (the last item in the array) _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV));deletes all items _GUICtrlListView_AddArray($LV, $LVIT);adds the new array back to the display Case $delete;CAN'T GET THIS TO WORK dim $deleteItem = GUICtrlRead(GUICtrlGetHandle($LV),1) MsgBox("","This is the selected item",$deleteItem) $deleteItem = GUICtrlRead($LV) _ArrayDelete($avArray, $deleteItem) Case $Display _ArrayDisplay($LVIT, "$LVIT (ListView Item Text) Array") EndSwitchWEnd Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
Jfish Posted December 31, 2008 Author Posted December 31, 2008 Never mind, sorry, solved it myself... Case $delete dim $deleteItem = _GUICtrlListView_GetSelectedIndices(GUICtrlGetHandle($LV)) _ArrayDelete($LVIT, $deleteItem) _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($LV));deletes all items _GUICtrlListView_AddArray($LV, $LVIT);adds the new array back to the display Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
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