Vadersapien Posted January 15, 2010 Posted January 15, 2010 I was trying to figure how to get the text of the selected item of a listview. So I came up with this, thinking it'd work:_GUICtrlListView_GetItemText($hListView, _GUICtrlListView_GetSelectedIndices($hListView))But it doesn't. What have I done wrong? Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
Moderators Melba23 Posted January 15, 2010 Moderators Posted January 15, 2010 Valdersapien,Have you looked at how the function returns the values? If you set $fArray to True: Array - With the following format [0] - Number of Items in array (n) [1] - First item index [2] - Second item index [n] - Last item index If you set $fArray to False: String - With the following format "0|1|2|n" M23 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
Vadersapien Posted January 16, 2010 Author Posted January 16, 2010 (edited) Oh! So GUICtrlListView_GetSelectedIndices() (with $fArray set to false) returns a string, not a number. I hadn't noticed this since I was using my listview with $LVS_SINGLECEL(or whatever it is)...So instead of creating reading an array (another variable!), I just converted the string to an integer:_GUICtrlListView_GetItemText($hListView, Int(_GUICtrlListView_GetSelectedIndices($hListView)))And it works perfect now.Thanks for pointing out that fact, I probably would have never noticed it!EDIT: Now how do I tell when an item is clicked on? GUIGetMsg() doesn't seem to work... Edited January 16, 2010 by Vadersapien Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
Fire Posted January 16, 2010 Posted January 16, 2010 And this way too: #include <GuiListView.au3> ;some code here and etc. $si=_GUICtrlListView_GetSelectedIndices($List1) local $AA = _GUICtrlListView_GetItemText(GUICtrlGetHandle($List1),$si,0) ; is fisrt column data of cource selected. So if you retrive data only from second row replace it with 1 [size="5"] [/size]
dantay9 Posted January 16, 2010 Posted January 16, 2010 Look at the help file example for _GUICtrlListView_Create. It has many messages about list views including the one you need, $NM_CLICK.
Vadersapien Posted January 16, 2010 Author Posted January 16, 2010 (edited) Alright...managed to simplify that WM_NOTIFY function mentioned in the help file: Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView ;~ Local $tBuffer $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ConsoleWrite('Clicked') EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY It works perfect, but can it be simplified any further? Edited January 17, 2010 by Vadersapien Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
dantay9 Posted January 16, 2010 Posted January 16, 2010 (edited) Not really. You could replace some of the variables to make the code shorter, but not simpler. Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) Switch HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Case $hWndListView Switch DllStructGetData($tNMHDR, "Code") Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ConsoleWrite('Clicked') EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited January 16, 2010 by dantay9
picaxe Posted January 16, 2010 Posted January 16, 2010 (edited) One simple way, if you only need single clickexpandcollapse popup; Listview get selected row(s) - gw #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Opt("MouseCoordMode", 2) Global $iLvLeft = 10, $iLvTop = 10, $iLvWidth = 280, $iLvHeight = 180 Global $iWidth = 300, $iHeight = 230 $hGUI = GUICreate("Test", $iWidth, $iHeight) $idListView = GUICtrlCreateListView("Items|SubItems", $iLvLeft, $iLvTop, $iLvWidth, $iLvHeight, $LVS_REPORT, $WS_EX_CLIENTEDGE) $hListview = GUICtrlGetHandle($idListView) _GUICtrlListView_SetExtendedListViewStyle($hListview, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) For $i = 0 To 10 _GUICtrlListView_AddItem($hListview, "Item" & $i) _GUICtrlListView_AddSubItem($hListview, $i, "SubItem" & $i, 1) Next $idSelected = GUICtrlCreateButton("Get Selected", 8, $iHeight - 30, $iWidth - 16, 20) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN If MouseGetPos(1) > ($iLvTop + 20) And MouseGetPos(1) < ($iLvHeight + $iLvTop) Then GetSelected() Case $idSelected GetSelected() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func GetSelected() ConsoleWrite(@LF) For $i = 0 To GUICtrlSendMsg($idListView, $LVM_GETITEMCOUNT, 0, 0) If GUICtrlSendMsg($idListView, $LVM_GETITEMSTATE, $i, 0x2) Then _ ConsoleWrite("Selected Row: " & $i & " Text: " & _GUICtrlListView_GetItemText($hListview, $i) & " " & _GUICtrlListView_GetItemText($hListview, $i, 1) & @LF) Next EndFuncOtherwise handling wm_notify would be prefered. Edited January 16, 2010 by picaxe
Vadersapien Posted January 16, 2010 Author Posted January 16, 2010 @Picaxe - Thanks for the suggestion. I like your method, it's a fair bit simpler to work with..I can't really decide between the two, especially when it comes to having two listviews(what then?) Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
picaxe Posted January 16, 2010 Posted January 16, 2010 (edited) @Picaxe - Thanks for the suggestion. I like your method, it's a fair bit simpler to work with..I can't really decide between the two, especially when it comes to having two listviews(what then?) More than one listviewexpandcollapse popup#include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Opt("MouseCoordMode", 2) Global $iLvLeft1 = 10, $iLvTop1 = 10, $iLvWidth1 = 280, $iLvHeight1 = 180 Global $iLvLeft2 = 300, $iLvTop2 = 10, $iLvWidth2 = 280, $iLvHeight2 = 180 Global $iWidth = 590, $iHeight = 230 $hGUI = GUICreate("Test", $iWidth, $iHeight) $idListView1 = GUICtrlCreateListView("Items|SubItems", $iLvLeft1, $iLvTop1, $iLvWidth1, $iLvHeight1, $LVS_REPORT, $WS_EX_CLIENTEDGE) $hListview1 = GUICtrlGetHandle($idListView1) _GUICtrlListView_SetExtendedListViewStyle($hListview1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $idListView2 = GUICtrlCreateListView("Items|SubItems", $iLvLeft2, $iLvTop2, $iLvWidth2, $iLvHeight2, $LVS_REPORT, $WS_EX_CLIENTEDGE) $hListview2 = GUICtrlGetHandle($idListView2) _GUICtrlListView_SetExtendedListViewStyle($hListview2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) GUISetState() For $i = 0 To 10 _GUICtrlListView_AddItem($hListview1, "Item" & $i) _GUICtrlListView_AddSubItem($hListview1, $i, "SubItem" & $i, 1) Next For $i = 0 To 10 _GUICtrlListView_AddItem($hListview2, "Item" & $i) _GUICtrlListView_AddSubItem($hListview2, $i, "SubItem" & $i, 1) Next $idSelected1 = GUICtrlCreateButton("Get Selected 1", $iLvLeft1, $iHeight - 30, $iLvWidth1, 20) $idSelected2 = GUICtrlCreateButton("Get Selected 2", $iLvLeft2, $iHeight - 30, $iLvWidth2, 20) While 1 Switch GUIGetMsg() Case $GUI_EVENT_PRIMARYDOWN $aPos = MouseGetPos() If $aPos[1] > ($iLvTop1 + 20) And $aPos[1] < ($iLvHeight1 + $iLvTop1) Then If $aPos[0] > $iLvLeft1 And $aPos[0] < ($iLvWidth1 + $iLvLeft1) Then GetSelected($idListView1) EndIf If $aPos[1] > ($iLvTop2 + 20) And $aPos[1] < ($iLvHeight2 + $iLvTop2) Then If $aPos[0] > $iLvLeft2 And $aPos[0] < ($iLvWidth2 + $iLvLeft2) Then GetSelected($idListView2) EndIf Case $idSelected1 GetSelected($idListView1) Case $idSelected2 GetSelected($idListView2) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func GetSelected($idLv) Switch $idLv Case $idListView1 $sLv = 1 $hLv = $hListview1 Case $idListView2 $sLv = 2 $hLv = $hListview2 EndSwitch For $i = 0 To GUICtrlSendMsg($idLv, $LVM_GETITEMCOUNT, 0, 0) If GUICtrlSendMsg($idLv, $LVM_GETITEMSTATE, $i, 0x2) Then _ ConsoleWrite("Listview " & $sLv & " Selected Row: " & $i & " Text: " & _GUICtrlListView_GetItemText($hLv, $i) & " " & _GUICtrlListView_GetItemText($hLv, $i, 1) & @LF) Next _GUICtrlListView_SetItemSelected($hLv, -1, False) EndFunc ;==>GetSelected Edited January 16, 2010 by picaxe
Vadersapien Posted January 17, 2010 Author Posted January 17, 2010 I made a small function to test if an item is selected. However it doesn't always work... Func _GUICtrlListView_ItemSelected($hGUI, $hListview) $ListviewPos = ControlGetPos($hGUI, '', $hListview) $CursorInfo = GUIGetCursorInfo($hGUI) If GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN And $CursorInfo[0] > $ListviewPos[0] And $CursorInfo[0] < ($ListviewPos[0] + $ListviewPos[2]) And _ $CursorInfo[1] > $ListviewPos[1] And $CursorInfo[1] < ($ListviewPos[1] + $ListviewPos[3]) And _GUICtrlListView_GetSelectedIndices($hListview) <> '' Then Return True Else Return False EndIf EndFunc I have a feeling it has to do with the GUIGetMsg() = $GUI_EVENT_PRIMARYDOWN bit... I could have used $CursorInfo[2] to see if the mouse button was down but it wouldn't work...it just returned false all the time(anyone know why?)... Try Pacfox, my Firefox theme.Try Power Eject, my windows gadget that allows you to eject most drives.Using AutoIt 3.3.4.0, Windows 7 Premium, Intel Core 2 Quad CPU @ 2.66ghz, 4gb RAM, Nvidia GeForce 9500GT Graphics Card & Samsung 22" Monitor.
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