tonycst Posted October 11, 2014 Share Posted October 11, 2014 Hi I have basic guictrlcreatelistview and it has few items in there created by guictrlcreatelistviewitem When i select item, i need something to happen. #include <GUIConstantsEx.au3> $Gui = GUICreate ("Title",200,200) $Listview = GUICtrlCreateListView("Sample",0,0,200,200) GuiCtrlCreateListViewItem ("Test Item", $Listview) GUISetState (@SW_SHOW,$Gui) While 1 $MSG = GUIGetMsg() If $MSG = $GUI_EVENT_CLOSE Then ExitLoop If $MSG = $Listview Then ;If button gives any messages to gui then MsgBox(0,'',"something") EndIf WEnd How do i go about getting MSG or do what ever it is i need in that loop ? I dont want to constantly readlistview with If Guictrlread ($listview) > "" Then it would be too much work and GUI would flicker. Link to comment Share on other sites More sharing options...
kylomas Posted October 11, 2014 Share Posted October 11, 2014 tonycst, This is how I do it... #include <GUIConstantsEx.au3> #include <GuiHeader.au3> #include <GuiListView.au3> $Gui = GUICreate ("Title",200,200) $Listview = GUICtrlCreateListView("Sample ",0,0,200,200) local $aLV[10] for $1 = 0 to 9 $aLV[$1] = GuiCtrlCreateListViewItem ("Test Item" & stringformat('%04i',$1), $Listview) Next GUISetState (@SW_SHOW,$Gui) While 1 switch guigetmsg() Case $GUI_EVENT_CLOSE exit case $Listview ; this only gets actioned when you click on the column header consolewrite(_GUICtrlHeader_GetItemText ( _GUICtrlListView_GetHeader ($Listview), 0) & @lf) case $aLV[0] to $aLV[ubound($aLV)-1] ; each member of this array coresponds to a LV item ConsoleWrite('Listview item selected = ' & stringtrimright(guictrlread(guictrlread($Listview)),1) & @CRLF) endswitch WEnd kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
tonycst Posted October 11, 2014 Author Share Posted October 11, 2014 (edited) Too cimplicated. Dont want to use any switches. I had to dig into my years old example and founf this. While 1 $Msg = GUIGetMsg() Local $GetClickedItem $GetClickedItem = GUICtrlRead($Listview) If $Msg = $GetClickedItem Then ;Show Selected If $GetClickedItem = 0 Then ElseIf $GetClickedItem = "" Then ElseIf $GetClickedItem > "" Then ;Do what ever. Clicked item is returning valid data _GUICtrlListView_SetItemState($ListView,$Index,$LVIS_FOCUSED,False) ;Unfocus item to stop it from triggering all the time EndIf EndIf Wend Seems to work only after clicking item. Otherwise it keeps returning data. (obviously, its in a loop) It does work. I just didnt understand how it worked Thanks ! Perhaps later i will find your example usefull, but almost 100% of all my codes i make i try to avoid switches and cases. Not sure exactly how they work. Seems easier for me to do it all in a loop. Edited October 11, 2014 by tonycst Link to comment Share on other sites More sharing options...
kylomas Posted October 12, 2014 Share Posted October 12, 2014 tonycst, I see. That spaghetti can be better expressed like this,... #include <GUIConstantsEx.au3> $Gui = GUICreate ("Title",200,200) $Listview = GUICtrlCreateListView("Sample ",0,0,200,200) local $aLV[10] for $1 = 0 to 9 $aLV[$1] = GuiCtrlCreateListViewItem ("Test Item" & stringformat('%04i',$1), $Listview) Next GUISetState (@SW_SHOW,$Gui) local $GetClickedItem While 1 $Msg = GUIGetMsg() if $msg = GUICtrlRead($Listview) and $msg <> 0 then ConsoleWrite(guictrlread(guictrlread($ListView)) & @CRLF) Wend kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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