lucamad Posted March 17, 2010 Share Posted March 17, 2010 Hi! I'm a AutoIt newbie. I add some items in my listview control, but i can't get the selected item info. I need to use icons in my listview, so i've used the _GUICtrlListView_AddItem function (the GUICtrlCreateListViewItem doesn't support icons...): #AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> GUICreate("Lokyweb Uploader", -1, -1, -1, -1, BitOr($WS_SIZEBOX, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX), $WS_EX_ACCEPTFILES);x il drag & drop $listview = GUICtrlCreateListView("List", 2, 40, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $LVS_SINGLESEL)) _GUICtrlListView_AddItem($listview, "test", 1) $button = GUICtrlCreateButton("Selected item", 10, 325) GUISetState() While (1) $msg = GUIGetMsg() if $msg = $button Then msgbox (0, "Selected item", GUICtrlRead(GUICtrlRead($listview)) ) EndIf If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd The msgbox always return a 0. There is a way to obtain a selected value in listview with icons? Thanks!! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 17, 2010 Moderators Share Posted March 17, 2010 lucamad, Welcome to the AutoIt forum. If you add the items to the ListView with the UDF, you need to carry on using the UDF on the items created: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> GUICreate("Lokyweb Uploader", -1, -1, -1, -1, BitOr($WS_SIZEBOX, $WS_SYSMENU, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX), $WS_EX_ACCEPTFILES);x il drag & drop $listview = GUICtrlCreateListView("List", 2, 40, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT, $LVS_SINGLESEL)) _GUICtrlListView_AddItem($listview, "test1", 1) _GUICtrlListView_AddItem($listview, "test2", 2) $button = GUICtrlCreateButton("Selected item", 10, 325) GUISetState() While (1) $msg = GUIGetMsg() if $msg = $button Then $iIndex = _GUICtrlListView_GetSelectedIndices($listview) msgbox (0, "Selected item", $iIndex) EndIf If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd This will return the 0-based index of the selected item. Be very careful mixing the buit-in commands and those from the UDF (regardless of which control type) as it can often end in tears. M23 AmbeR- and Netol 2 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...
lucamad Posted March 18, 2010 Author Share Posted March 18, 2010 Melba23 Many thanks! In fact I've spent a lot of time for this problem... Your corrections work fine. I don't know why the behavior is different using UDF functions (a listview is already a listview ..or not? ). This script language is very interesting and adaptable, I like it very much. THX Melba Luca Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 18, 2010 Moderators Share Posted March 18, 2010 lucamad,a listview is already a listview ..or not? "Not" - or at least "Not quite"! When you create a ListViewItem with the built-in command GUICtrlCreateListViewItem, AutoIt returns an internal ControlID and you can then use (most of) the other builtin GUICtrl* commands on the item using the ControlID to identify it.When you use the UDF's _GUICtrlListView_AddItem command, it returns the unique Windows handle of the control, which means that (most of) the built-in Autoit commands will not work as there is no ControlID to identify the control to AutoIt's internal coding.That is a bit simplified, but shows in brief why you should not, in general, mix the built-in and UDF commands for a control. Go for one or the other - although there are plenty of examples where coders have done it and it works! I hope that makes it a bit clearer. 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 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