PartyPooper Posted July 2, 2008 Share Posted July 2, 2008 Having never had to use GUICtrlCreateListView or GUICtrlCreateListViewItem previously, I'm fumbling my way through some code and would appreciate any help. I'm writing up some code using the OnEvent mode and can't seem to work out why GUICtrlCreateListView doesn't work with GUICtrlSetOnEvent. Essentially, I am trying to detect whenever I click on a Listview without having to put the detection routine inside a loop. I was hoping that GUICtrlSetOnEvent would work by simply firing off an event whenever I clicked on the Listview - it doesn't. Here's an example of what I mean: $listview = GUICtrlCreateListView("col1|col2|col3 ", 10, 10, 200, 150, BitOR($LVS_NOSORTHEADER, $LVS_REPORT, $LVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) GUICtrlSetOnEvent($listview, "_onclick") Since this didn't seem to work I thought about trying to detect whenever I click on a Listviewitem (hoping that my listview would never be blank), again without having to put the detection routine inside a loop. I thought the following would work but again, it didn't: $listviewitem = GUICtrlCreateListViewItem("item1 ", $listview) GUICtrlSetOnEvent($listviewitem, "_onclick") Firstly, can someone explain why GUICtrlSetOnEvent doesn't seem to work with the Listview GUICtrl's, and secondly, to get this to work, do I need to investigate using the GUIRegisterMsg? - I hope not because it adds an unwelcome complexity to what should be a simple process. I should point out I'm not concerned with detecting the actual item index within the listview, just that I've clicked on it. Also, none of my listviewitems have checkboxes. Link to comment Share on other sites More sharing options...
rasim Posted July 2, 2008 Share Posted July 2, 2008 PartyPooperHi! See a _GUICtrlListView_Create() function in the help file. Also try to find at the forum:Example1Example2 Link to comment Share on other sites More sharing options...
PartyPooper Posted July 2, 2008 Author Share Posted July 2, 2008 Yeah thanks rasim, I had a quick look at both those links before I posted, neither worked on non-checkbox lists or outside of a loop. I'll have another look and do some more playing around to see if I can find a solution. I'll also give the UDF another look (I assumed it was similar to the inbuilt function and didn't bother looking any further). Link to comment Share on other sites More sharing options...
PartyPooper Posted July 2, 2008 Author Share Posted July 2, 2008 Ok, had a play around with the code in one of the links rasim posted and I got it to work, however, I'm not sure how to trigger an item after its hovered over. Heres what I've got working so far. As you can see, clicking on the item triggers an event and the item is selected after I hover over it for a time but it's not triggering an event. Is there a UDF function that would help? #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Opt("GuiOnEventMode", 1) Global $Selected = 0 Global $avLVItems[5] Main() While 1 Sleep(20) WEnd Func Main() $GUI = GUICreate("Test") GUISetOnEvent(-3, "Quit") $ListView = GUICtrlCreateListView("Column1", 20, 40, 200, 200, -1, $WS_EX_OVERLAPPEDWINDOW) _GUICtrlListView_SetExtendedListViewStyle($ListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_TRACKSELECT)) For $i = 0 To 4 $avLVItems[$i] = GUICtrlCreateListViewItem("Item" & $i, $ListView) GUICtrlSetOnEvent(-1, "_LVHit") Next GUISetState() EndFunc ;==>Main Func Quit() Exit EndFunc ;==>Quit Func _LVHit() MsgBox(0, '', 'do stuff') EndFunc ;==>_LVHit Link to comment Share on other sites More sharing options...
rasim Posted July 3, 2008 Share Posted July 3, 2008 Try this: expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> Global $LastItem = -1 $hGUI = GUICreate("Test GUI", 300, 200) $hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems", 10, 10, 280, 180, $LVS_REPORT, $WS_EX_CLIENTEDGE) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_TRACKSELECT)) For $i = 1 To 10 _GUICtrlListView_AddItem($hListView, "Item " & $i) _GUICtrlListView_AddSubItem($hListView, $i - 1, "SubItem " & $i, 1) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $hWndFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iItem = DllStructGetData($tInfo, "Item") If $iItem <> $LastItem Then $LastItem = $iItem ConsoleWrite("!> Item: " & $iItem + 1 & " is selected" & @LF) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Link to comment Share on other sites More sharing options...
PartyPooper Posted July 3, 2008 Author Share Posted July 3, 2008 Thanks rasim, I'll have a play around with it. I'm having second-thoughts about firing off an event on hover - it may get a little annoying. Instead, I might look at trying to get a tooltip displaying additional stuff about the item currently underneath the cursor. 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