PetterBomban Posted December 11, 2015 Share Posted December 11, 2015 Hi folks.I'm trying to automate blocking of students network access by bulk, instead of blocking each and every class manually.So far so good, I have managed to make it work. Now I have to create a GUI for it, so that the other guys at the office can use it.I'm having some trouble though. Instead of outputting the text in my listview, it outputs a number, no matter what I select.Here are some screenshots to better explain:expandcollapse popup#include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> mainGUI() Func mainGUI() Local $msg Local $GUI = GUICreate("Menu", 1000, 850) Local $button1 = GUICtrlCreateButton("Button 1", 5, 30, 100, 25) Local $listOfGroups = GUICtrlCreateListView("", 5, 100, 180, 500, BitOR($LBS_STANDARD, $LBS_EXTENDEDSEL, $WS_VSCROLL, $LVS_SHOWSELALWAYS)) Local $listOfGroupsItems = ["test", "testd", "asdasd", "asdasdasdasdasd"] For $groupItem in $listOfGroupsItems GUICtrlCreateListViewItem($groupItem, $listOfGroups) Next GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $button1 $testRead = GUICtrlRead($listOfGroups) MsgBox(0, 'Button 1', $testRead) EndSelect WEnd EndFunc ;==> mainGUI() Link to comment Share on other sites More sharing options...
Developers Jos Posted December 11, 2015 Developers Share Posted December 11, 2015 These are the handles returned by the GUICtrlCreateListViewItem() statement which you aren't capturing.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
PetterBomban Posted December 11, 2015 Author Share Posted December 11, 2015 (edited) These are the handles returned by the GUICtrlCreateListViewItem() statement which you aren't capturing.JosCould you give me an example of how it is done? Edit: Found out how: GUICtrlRead(GUICtrlRead($listview)).But now I am having another problem. How do I print out all the values selected? Currently, only one value at a time will show up.Any pointers? Edited December 11, 2015 by PetterBomban Link to comment Share on other sites More sharing options...
BrewManNH Posted December 11, 2015 Share Posted December 11, 2015 Use _GUICtrlListView_GetSelectedIndices and loop through the array to find out what the text/information is from those selected indices. PetterBomban 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
PetterBomban Posted December 15, 2015 Author Share Posted December 15, 2015 I think I solved it.$items = _GUICtrlListView_GetSelectedIndices($listOfGroups, True) For $item in $items $rowName = _GUICtrlListView_GetItemText($listOfGroups, Number($item), 0) ConsoleWrite($rowName) Next Link to comment Share on other sites More sharing options...
BrewManNH Posted December 16, 2015 Share Posted December 16, 2015 I wouldn't use a For In loop with the array returned by the first function, the first element of the array is going to be the count of selected items in the listview. This is going to give you wrong results. You should use a regular For/Next loop instead and start the loop at 1 instead of zero. PetterBomban 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
PetterBomban Posted December 16, 2015 Author Share Posted December 16, 2015 (edited) I wouldn't use a For In loop with the array returned by the first function, the first element of the array is going to be the count of selected items in the listview. This is going to give you wrong results. You should use a regular For/Next loop instead and start the loop at 1 instead of zero.Thanks a ton! It's as you said, the For..In loop made weird things happen.$items = _GUICtrlListView_GetSelectedIndices($listOfGroups, True) $itemsNum = UBound($items) For $i = 1 To $itemsNum - 1 $rowName = _GUICtrlListView_GetItemText($listOfGroups, Number($items[$i]), 0) ConsoleWrite(" - ") ConsoleWrite($rowName) Next Edited December 16, 2015 by PetterBomban 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