littlebigman Posted March 29 Share Posted March 29 Hello, This is my first try at the ListView control, and am having some issues. The helpfile didn't help: No event is triggered when I click/double-click How to display a horizontal scrollbar How to enable multi-selection? Here's the code: #Region ### START Koda GUI section $Form1 = GUICreate("My form", 615, 437, 270, 124) $ListView1 = GUICtrlCreateListView("Date|Title|Guid|URL", 8, 8, 594, 374) $Button1 = GUICtrlCreateButton("Download", 8, 392, 595, 25) #EndRegion ### END Koda GUI section ### For $index = 0 to UBound($mst, $UBOUND_ROWS) - 1 Local $idItem1 = GUICtrlCreateListViewItem("My date|My title|My GUID|my URL", $ListView1) Next GUISetState(@SW_SHOW) While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;no event when (double-clicking) ;how to display hz scrollbar? ;how to enable multiselection? Case $ListView1 MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($ListView1)) Case $Button1 MsgBox($MB_OK,"Button","Dload") EndSwitch WEnd Thank you. Link to comment Share on other sites More sharing options...
Solution Andreik Posted March 29 Solution Share Posted March 29 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $g_hListView Example() Func Example() Local $hGUI, $hImage $hGUI = GUICreate("ListView Create (v" & @AutoItVersion & ")", 400, 300) $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268, BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $WS_HSCROLL)) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ; Add columns _GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1") _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1") _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndListView = $g_hListView If Not IsHWnd($g_hListView) Then $hWndListView = GUICtrlGetHandle($g_hListView) Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam) ConsoleWrite('Double clicked item: ' & $tNMITEMACTIVATE.Index & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited March 29 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
littlebigman Posted March 29 Author Share Posted March 29 (edited) Thanks. Since that control is located in the "Win32" section of the toolbar in Koda, I did suspect it might require using different functions to access its full potential, although the helpfile shows the basic functions support clicking on a row at least through the GUICtrlGetState() function: While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview)), 2) Case $idListview MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2) EndSwitch WEnd --- Edit: Maybe there is a work-around, but it's not as easy to use as the plain GUICtrlCreateListView(): Doesn't support creating + inserting multiple columns in one go with the "|" sign between columns Requires calling _GUICtrlListView_AddItem() to add a row, and then _GUICtrlListView_AddSubItem() to add other columns of that same row Doesn't work with the default GUI loop Requires registering a WM_NOTIFY() WM_NOTIFY() relies on the ListView handle which must be global to be accessible from within that function Edit: To insert items, there's at least the alternative _GUICtrlListView_AddArray() Edited March 29 by littlebigman Link to comment Share on other sites More sharing options...
Andreik Posted March 29 Share Posted March 29 You can create a list view and items with native functions and then use _GUICtrlListView_*() functions: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $cListView Local $hGUI = GUICreate("ListView Create (v" & @AutoItVersion & ")", 400, 300) Local $iStyle = BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS, $WS_HSCROLL) Local $iExStyle = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES) $cListView = GUICtrlCreateListView("Col1|Col2|Col3", 2, 2, 394, 268, $iStyle, $iExStyle) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUICtrlCreateListViewItem('Item 0 - Subitem 0|Item 0 - Subitem 1|Item 0 - Subitem 2', $cListView) GUICtrlCreateListViewItem('Item 1 - Subitem 0|Item 1 - Subitem 1|Item 1 - Subitem 2', $cListView) GUICtrlCreateListViewItem('Item 2 - Subitem 0|Item 2 - Subitem 1|Item 2 - Subitem 2', $cListView) _GUICtrlListView_SetColumnWidth($cListView, 0, 120) _GUICtrlListView_SetColumnWidth($cListView, 1, 120) _GUICtrlListView_SetColumnWidth($cListView, 2, 120) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hListview If Not IsHWnd($cListView) Then $hListview = GUICtrlGetHandle($cListView) Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListview Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam) ConsoleWrite('Double clicked item: ' & $tNMITEMACTIVATE.Index & ', Subitem: ' & $tNMITEMACTIVATE.Subitem & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc When the words fail... music speaks. Link to comment Share on other sites More sharing options...
littlebigman Posted March 29 Author Share Posted March 29 Much better, thank you 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