Moderators JLogan3o13 Posted December 30, 2014 Moderators Posted December 30, 2014 (edited) I have a GUI with several ListViews, and am trying to obtain the ItemText from just the "active" one. Looking to group the listviews so only one is active at a time. Below is a reproducer to show the basic GUI framework. Each of the listviews has multiple columns, which I use _GUICtrlListView_GetItemTextArray to get the text of. What I am after is basically similar to grouping radio buttons or checkboxes; when one listview is active the others are not. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> $hGUI_Main = GUICreate("Test", 500, 350) GUISetState(@SW_SHOW) $btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30) $sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250) _GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView, 0, 100) _GUICtrlListView_SetColumnWidth($sListView, 1, 100) $sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250) _GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView2, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView2, 0, 100) _GUICtrlListView_SetColumnWidth($sListView2, 1, 100) _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI") _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1) _GUICtrlListView_AddItem($sListView, "Adobe Reader XI") _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1) _GUICtrlListView_AddItem($sListView, "Camtasia Studio") _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1) _GUICtrlListView_AddItem($sListView, "FA3") _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x86") _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x64") _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x86") _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x64") _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnGo $aTextListView = _GUICtrlListView_GetItemTextArray($sListView) $aTextListView2 = _GUICtrlListView_GetItemTextArray($sListView2) MsgBox(0, "", "Active Selections are: " & $aTextListView[1] & " and " & $aTextListView2[1]) EndSwitch WEnd GUIDelete() In the past I have done this with WM_NOTIFY, when the user double clicks on a selection it can pull the text regardless of which listview it is in. But it has always been double-click driven, and single-column listviews, rather than the way I am attempting it here. I'm just curious if anyone has ever done anything similar, and if I am overlooking an obvious and simple way of doing this. Edited January 9, 2015 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators JLogan3o13 Posted January 7, 2015 Author Moderators Posted January 7, 2015 To close the loop on this, I never did come up with a better solution. I cobbled the below together, using radio buttons (grouped together if necessary), but that is just ugly. Putting it up on the shelf for the time being. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> $hGUI_Main = GUICreate("Test", 500, 350) GUISetState(@SW_SHOW) $btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30) $sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250) _GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView, 0, 100) _GUICtrlListView_SetColumnWidth($sListView, 1, 100) $sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250) _GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView2, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView2, 0, 100) _GUICtrlListView_SetColumnWidth($sListView2, 1, 100) _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI") _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1) _GUICtrlListView_AddItem($sListView, "Adobe Reader XI") _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1) _GUICtrlListView_AddItem($sListView, "Camtasia Studio") _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1) _GUICtrlListView_AddItem($sListView, "FA3") _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x86") _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x64") _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x86") _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x64") _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1) $rApps = GUICtrlCreateRadio("Applications", 10, 270, 100, 17) $rOS = GUICtrlCreateRadio("OS", 250, 270, 100, 17) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnGo If GUICtrlRead($rApps) = 1 Then $aTemp = _GUICtrlListView_GetItemTextArray($sListView) MsgBox(0, "", $aTemp[1]) ElseIf GUICtrlRead($rOS) = 1 Then $aTemp = _GUICtrlListView_GetItemTextArray($sListView2) MsgBox(0, "", $aTemp[1]) Else ;Do something else EndIf EndSwitch WEnd GUIDelete() "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Moderators Solution Melba23 Posted January 7, 2015 Moderators Solution Posted January 7, 2015 JLogan3o13,I missed this when you posted the first time. This is what I do in my GUIListViewEx UDF - look for a single click on a ListView and save the handle in a Global variable:expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $hCurrListView, $aListView[2] $hGUI_Main = GUICreate("Test", 500, 350) GUISetState(@SW_SHOW) $btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30) $sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250) $aListView[0] = $sListView _GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView, 0, 100) _GUICtrlListView_SetColumnWidth($sListView, 1, 100) $sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250) $aListView[1] = $sListView2 _GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView2, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView2, 0, 100) _GUICtrlListView_SetColumnWidth($sListView2, 1, 100) _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI") _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1) _GUICtrlListView_AddItem($sListView, "Adobe Reader XI") _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1) _GUICtrlListView_AddItem($sListView, "Camtasia Studio") _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1) _GUICtrlListView_AddItem($sListView, "FA3") _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x86") _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x64") _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x86") _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x64") _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnGo $aTemp = _GUICtrlListView_GetItemTextArray($hCurrListView) MsgBox(0, "", $aTemp[1]) EndSwitch WEnd GUIDelete() Func _WM_NOTIFY($nWnd, $iMsg, $wParam, $lParam) Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF) = $NM_CLICK Then ; Code $hCurrListView = DllStructGetData($tStruct, 1) ; ListView handle EndIf EndFuncAny use? 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
Moderators JLogan3o13 Posted January 7, 2015 Author Moderators Posted January 7, 2015 (edited) I in fact was just giving your UDF another look to see if I might use it for this scenario. This works well for the reproducer I posted; I will spend some time this afternoon plugging this into the actual script to see if it works. As always, many thanks. Edited January 7, 2015 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Yashied Posted January 7, 2015 Posted January 7, 2015 (edited) You can use NM_SETFOCUS and NM_KILLFOCUS as shown below. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $hFocus = 0 $hGUI_Main = GUICreate("Test", 500, 350) $btnGo = GUICtrlCreateButton("Go", 10, 300, 100, 30) $sListView = _GUICtrlListView_Create($hGUI_Main, "Application", 10, 10, 200, 250) _SetStyle($sListView, $WS_TABSTOP, 1) _GUICtrlListView_SetExtendedListViewStyle($sListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView, 0, 100) _GUICtrlListView_SetColumnWidth($sListView, 1, 100) $sListView2 = _GUICtrlListView_Create($hGUI_Main, "O/S", 250, 10, 200, 250) _SetStyle($sListView2, $WS_TABSTOP, 1) _GUICtrlListView_SetExtendedListViewStyle($sListView2, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) _GUICtrlListView_AddColumn($sListView2, "Resource ID") _GUICtrlListView_SetColumnWidth($sListView2, 0, 100) _GUICtrlListView_SetColumnWidth($sListView2, 1, 100) _GUICtrlListView_AddItem($sListView, "Adobe Acrobat XI") _GUICtrlListView_AddSubItem($sListView, 0, "P01000CE", 1) _GUICtrlListView_AddItem($sListView, "Adobe Reader XI") _GUICtrlListView_AddSubItem($sListView, 1, "P01000AA", 1) _GUICtrlListView_AddItem($sListView, "Camtasia Studio") _GUICtrlListView_AddSubItem($sListView, 2, "P010008F", 1) _GUICtrlListView_AddItem($sListView, "FA3") _GUICtrlListView_AddSubItem($sListView, 3, "P01000B7", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x86") _GUICtrlListView_AddSubItem($sListView2, 0, "P0100016", 1) _GUICtrlListView_AddItem($sListView2, "Windows 7 x64") _GUICtrlListView_AddSubItem($sListView2, 1, "P0100015", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x86") _GUICtrlListView_AddSubItem($sListView2, 2, "P0100019", 1) _GUICtrlListView_AddItem($sListView2, "Windows 8 x64") _GUICtrlListView_AddSubItem($sListView2, 3, "P0100020", 1) ;$rApps = GUICtrlCreateRadio("Applications", 10, 270, 100, 17) ;$rOS = GUICtrlCreateRadio("OS", 250, 270, 100, 17) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnGo If $hFocus Then $aTemp = _GUICtrlListView_GetItemTextArray($hFocus) If ($aTemp[0] <> 0) And ($aTemp[1] <> "") Then MsgBox(0, "", $aTemp[1], 0, $hGUI_Main) EndIf EndIf EndSwitch WEnd GUIDelete() Func _SetStyle($hWnd, $iStyle, $fSet, $fExStyle = 0, $fUpdate = 0) Local $Flag, $Style If $fExStyle Then $Flag = -20 Else $Flag = -16 EndIf $Style = _WinAPI_GetWindowLong($hWnd, $Flag) If Not $fSet Then _WinAPI_SetWindowLong($hWnd, $Flag, BitAND($Style, BitNOT($iStyle))) Else _WinAPI_SetWindowLong($hWnd, $Flag, BitOR($Style, $iStyle)) EndIf If $fUpdate Then _WinAPI_InvalidateRect($hWnd, 0, 0) EndIf EndFunc ;==>_SetStyle Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMIA = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $hTarget = DllStructGetData($tNMIA, 'hWndFrom') Local $ID = DllStructGetData($tNMIA, 'Code') Switch $hWnd Case $hGUI_Main Switch $hTarget Case $sListView, $sListView2 Switch $ID Case $LVN_BEGINDRAG Return 0 Case $NM_KILLFOCUS $hFocus = $hTarget Case $NM_SETFOCUS _SetStyle($hTarget, $LVS_SHOWSELALWAYS, 1) If ($hFocus) And ($hFocus <> $hTarget) Then _SetStyle($hFocus, $LVS_SHOWSELALWAYS, 0, 0, 1) EndIf $hFocus = $hTarget EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited January 7, 2015 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
Moderators JLogan3o13 Posted January 9, 2015 Author Moderators Posted January 9, 2015 Thanks to both of you. I was able to make it work very well, even with a number of listviews. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
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