FlintBrenick Posted June 18, 2010 Share Posted June 18, 2010 I have a one dimensional array that I'm displaying in a list control and I'm trying to create three functions for the list control. I want to be able to move an item up on the list, down on the list, and remove and item from the list (and the array at the same time). Unless there is a functions that I've overlooked, the best way I know to do this to get the index number of which line is selected on the list, process the appropriate function in the array, then set my list to match my array. The only problem is that I don't know how to get the index number so that I know which line on the list is selected. The only thing I can figure out is that I can get the text of the line that is selected and then compare it to each item in the array until I find a match and just hope that the item selected isn't a duplicated further down on this list. So the root of the question is, how to I get the index number of the line that is selected in a list control? Any other ideas on how I could streamline the process would be greatly appreciated. Thanks guys! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 18, 2010 Moderators Share Posted June 18, 2010 (edited) FlintBrenick,If you were to consider using a ListView rather than a ListBox, then the code I posted here will do just what you want (and a bit more!). Or if you insist on a ListBox, you can use this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Include <GuiListBox.au3> #include <WinAPI.au3> $fDblClk = False Global $sList = "One|Two|Three|Four" $hGUI = GUICreate("Test", 500, 500) $hListBox = GUICtrlCreateList("", 10, 10, 200, 200, $LBS_NOTIFY ) $hList_Handle = GUICtrlGetHandle($hListBox) GUICtrlSetData($hListBox, $sList) GUISetState() GUIRegisterMsg($WM_COMMAND, "WM_ListBox_DoubleClick") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch If $fDblClk = True Then $fDblClk = False $iIndex = _GUICtrlListBox_GetCaretIndex($hListBox) ConsoleWrite($iIndex & @CRLF) EndIf WEnd ; React to double clicks on listbox Func WM_ListBox_DoubleClick($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $lParam If BitAND($wParam, 0xFFFF) = $hListBox Then ; LoWOrd = ControlID If BitShift($wParam, 16) = 2 Then $fDblClk = True ; HiWord = $LBN_DBLCLK EndIf Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMANDI hope that helps. M23Edit. Added a bit more! Edited June 18, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Spiider11 Posted August 15, 2010 Share Posted August 15, 2010 Thanks man that helped me a lot to understand how ListBox works 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