amf Posted April 11, 2010 Share Posted April 11, 2010 (edited) Hi all I have a stange little problem... or actually two. What I want to do is get the index of the selected item in a List View. I wrote this code and when I try to get the index in function: Lst_ValuesClick() and show it with: MsgBox(0, "$SelIndex: ", $SelIndex), the value of the index is shown correct. When I use it in: MsgBox(0, "$SelItemTxt", _GUICtrlListView_GetItemText($Lst_Values, $SelIndex)), the value is empty. Another thing is that I want to have the selected value to the editbox by clicking on it in the List View, but nothing happens when I click the values... only when I click on the Columnname. Anyone have any ideas? Here is the code... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) $Frm_Main = GUICreate("Main", 202, 270, 193, 123) GUISetOnEvent($GUI_EVENT_CLOSE, "Frm_MainClose") $Lst_Values = GUICtrlCreateListView("Items", 16, 16, 169, 175) GUICtrlSetOnEvent(-1, "Lst_ValuesClick") $Inp_Value = GUICtrlCreateInput("", 16, 200, 169, 21) $Btn_Add = GUICtrlCreateButton("Add to list", 16, 232, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "Btn_AddClick") $Btn_Delete = GUICtrlCreateButton("Delete", 112, 232, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "Btn_DeleteClick") GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func Btn_AddClick() _GUICtrlListView_AddItem($Lst_Values, GUICtrlRead($Inp_Value)) EndFunc Func Btn_DeleteClick() _GUICtrlListView_DeleteItemsSelected($Lst_Values) ;deleting selected item EndFunc Func Frm_MainClose() Exit EndFunc Func Lst_ValuesClick() $SelIndex = _GUICtrlListView_GetSelectedIndices($Lst_Values)) MsgBox(0, "$SelIndex: ", $SelIndex) MsgBox(0, "$SelItemTxt", _GUICtrlListView_GetItemText($Lst_Values, $SelIndex)) EndFunc Edited April 11, 2010 by amf Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 11, 2010 Moderators Share Posted April 11, 2010 amf,Answer 1: _GUICtrlListView_GetItemText is one of those UDF function that requires the handle of the control and not its ControlID.Answer 2: Try using GUIRegisterMsg to react to clicks on the ListView. It is best to use double clicks, as you need single clicks to actually select the value. Then you get something like this:expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> Global $fDblClk = False Opt("GUIOnEventMode", 1) $Frm_Main = GUICreate("Main", 202, 270, 193, 123) GUISetOnEvent($GUI_EVENT_CLOSE, "Frm_MainClose") $Lst_Values = GUICtrlCreateListView("Items", 16, 16, 169, 175) $Lst_Handle = GUICtrlGetHandle(-1) $Inp_Value = GUICtrlCreateInput("", 16, 200, 169, 21) $Btn_Add = GUICtrlCreateButton("Add to list", 16, 232, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "Btn_AddClick") $Btn_Delete = GUICtrlCreateButton("Delete", 112, 232, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "Btn_DeleteClick") GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_ListView_DoubleClick") While 1 Sleep(10) If $fDblClk = True Then $fDblClk = False Lst_ValuesClick() EndIf WEnd Func Btn_AddClick() _GUICtrlListView_AddItem($Lst_Values, GUICtrlRead($Inp_Value)) EndFunc Func Btn_DeleteClick() _GUICtrlListView_DeleteItemsSelected($Lst_Values) ;deleting selected item EndFunc Func Frm_MainClose() Exit EndFunc Func Lst_ValuesClick() $SelIndex = _GUICtrlListView_GetSelectedIndices($Lst_Values) MsgBox(0, "$SelIndex: ", $SelIndex) MsgBox(0, "$SelItemTxt", _GUICtrlListView_GetItemText($Lst_Handle, $SelIndex)) EndFunc ; React to double clicks on recent ListView Func WM_ListView_DoubleClick($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return If DllStructGetData($tNMHDR, 1) = $Lst_Handle Then If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True EndIf $tNMHDR = 0 Return $GUI_RUNDEFMSG EndFunc ;==>WM_ListView_DoubleClickI hope that helps. 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...
amf Posted April 11, 2010 Author Share Posted April 11, 2010 Ahh... works like a charm And a nice little function for the dblclk to. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 11, 2010 Moderators Share Posted April 11, 2010 amf, My pleasure. 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