AramisResearch Posted August 2, 2006 Share Posted August 2, 2006 If I missed this in the documentation I apologize in advance. In reality, I can barely code my way out of a paperbag and I am busy trying to learn. Here is what I would like to do: I am creating a GUI with two tabs - this I can do - and in one tab (labelled "Server") I would like to have it create a listview whose items are pulled from a pre-populated text file. Each item would be the name of a server on the network. The trouble here is that I can read the file, dump the lines in the file to an array, and show the lines in a ListView, but I can only select one at a time. I would like to be able to select more than one item on my list using the TAB and CTRL and SHIFT keys as is customary in Windows, have it read my selections, and then execute the chosen operation on those items. BTW, the intention here is to hook the free SysInternals PSEXEC utility into the GUI and execute things against the servers chosen from the list. This could be used to deploy patches or whatever else one mught imagine doing with a list of servers. Here is the relevant chunk of code: Func _GUISetup() $PathtoPatch = "C:\Patches\" Local $LineCounter = 1 Local $listview GUICreate("Patch Panel", 900, 500) $Patch = GUICtrlCreateButton("Patch", 225, 470, 50, 20) GUICtrlCreateTab(2, 2, 498, 460) $PatchTab = GUICtrlCreateTabItem("Patches") $PathtoPatchLabel = GUICtrlCreateLabel("Path to Patch: ", 10, 30, 100, 18) $PathtoPatchInput = GUICtrlCreateInput($PathtoPatch, 90, 30, 100, 18) $ServerTab = GUICtrlCreateTabItem("Servers") $ServerList = FileOpen("C:\ServerList.txt", 0) While 1 $Line = FileReadLine($ServerList) If @error = -1 Then ExitLoop $ServerArray[$LineCounter] = $Line $LineCounter = $LineCounter + 1 WEnd $ListView = GUICtrlCreateListView("Server List", 10, 60, 400, 200) For $X = 1 to $LineCounter - 1 $ListItem[$X] = GUICtrlCreateListViewItem($ServerArray[$X], $ListView) Next GuiSetState() While GuiGetMsg() <> $Patch WEnd EndFunc As you can tell, right now it's an empty shell of a GUI. Thanks, -Chris Link to comment Share on other sites More sharing options...
GaryFrost Posted August 2, 2006 Share Posted August 2, 2006 try: $ListView = GUICtrlCreateListView("Server List", 10, 60, 400, 200,BitOR($LVS_SHOWSELALWAYS,$LVS_REPORT)) SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
AramisResearch Posted August 2, 2006 Author Share Posted August 2, 2006 try: $ListView = GUICtrlCreateListView("Server List", 10, 60, 400, 200,BitOR($LVS_SHOWSELALWAYS,$LVS_REPORT)) Beautiful! Thank you. Link to comment Share on other sites More sharing options...
AramisResearch Posted August 2, 2006 Author Share Posted August 2, 2006 OK, you probably knew this question was next: So I can select multiple lines from my list now (thank you). I am having problems using GUICtrlRead() to read in just the items I selected. I can read *nothing* (i.e. all null values or zero), or it will read all the servers in the list quite happily. I have used GUICtrlRead before to grab stuff from inputboxes and radio buttons, but this one has thrown me. expandcollapse popup;============================================ ; Declarations | ;============================================ #include <GUIConstants.au3> Global $PathtoPatch Dim $ServerArray[500], $ListItem[500], $Selected[500] ;============================================ ; Main | ;============================================ _GUISetup() ;============================================ ; _GUISetup | ;============================================ Func _GUISetup() $PathtoPatch = "C:\Patches\" Local $LineCounter = 1 Local $listview, $Pressed GUICreate("Patch Panel", 900, 500) $Patch = GUICtrlCreateButton("Patch", 225, 470, 50, 20) GUICtrlCreateTab(2, 2, 498, 460) $PatchTab = GUICtrlCreateTabItem("Patches") $PathtoPatchLabel = GUICtrlCreateLabel("Path to Patch: ", 10, 30, 100, 18) $PathtoPatchInput = GUICtrlCreateInput($PathtoPatch, 90, 30, 100, 18) $ServerTab = GUICtrlCreateTabItem("Servers") $ServerList = FileOpen("C:\ServerList.txt", 0) While 1 $Line = FileReadLine($ServerList) If @error = -1 Then ExitLoop $ServerArray[$LineCounter] = $Line $LineCounter = $LineCounter + 1 WEnd $ListView = GUICtrlCreateListView("Server List", 10, 60, 400, 200, BitOR($LVS_SHOWSELALWAYS,$LVS_REPORT)) For $X = 1 to $LineCounter - 1 $ListItem[$X] = GUICtrlCreateListViewItem($ServerArray[$X], $ListView) $Selected[$X] = GUICtrlRead($ListItem[$X]) Next GuiSetState() While 1 $Pressed = GUIGetMsg() Select Case $Pressed = $Patch For $X = 1 to $LineCounter - 1 MsgBox(0, "Selected Server #" & $X, $Selected[$X]) Next ExitLoop Case $Pressed = $GUI_EVENT_CLOSE ExitLoop EndSelect Wend EndFunc Link to comment Share on other sites More sharing options...
GaryFrost Posted August 2, 2006 Share Posted August 2, 2006 Not tested, don't have the data, you'll need beta tho expandcollapse popup;============================================ ; Declarations | ;============================================ #include <GUIConstants.au3> #include <GuiListView.au3> Global $PathtoPatch Dim $ServerArray[500], $ListItem[500], $Selected[500] ;============================================ ; Main | ;============================================ _GUISetup() ;============================================ ; _GUISetup | ;============================================ Func _GUISetup() $PathtoPatch = "C:\Patches\" Local $LineCounter = 1 Local $listview, $Pressed GUICreate("Patch Panel", 900, 500) $Patch = GUICtrlCreateButton("Patch", 225, 470, 50, 20) GUICtrlCreateTab(2, 2, 498, 460) $PatchTab = GUICtrlCreateTabItem("Patches") $PathtoPatchLabel = GUICtrlCreateLabel("Path to Patch: ", 10, 30, 100, 18) $PathtoPatchInput = GUICtrlCreateInput($PathtoPatch, 90, 30, 100, 18) $ServerTab = GUICtrlCreateTabItem("Servers") $ServerList = FileOpen("C:\ServerList.txt", 0) While 1 $Line = FileReadLine($ServerList) If @error = -1 Then ExitLoop $ServerArray[$LineCounter] = $Line $LineCounter = $LineCounter + 1 WEnd $listview = GUICtrlCreateListView("Server List", 10, 60, 400, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT)) For $X = 1 To $LineCounter - 1 $ListItem[$X] = GUICtrlCreateListViewItem($ServerArray[$X], $listview) $Selected[$X] = GUICtrlRead($ListItem[$X]) Next GUISetState() While 1 $Pressed = GUIGetMsg() Select Case $Pressed = $Patch Local $a_indices = _GUICtrlListViewGetSelectedIndices($listview, 1) If (IsArray($a_indices)) Then Local $i For $i = 1 To $a_indices[0] MsgBox(0, "Selected", _GUICtrlListViewGetItemText($listview, $a_indices[$i])) Next EndIf Case $Pressed = $GUI_EVENT_CLOSE ExitLoop EndSelect WEnd EndFunc ;==>_GUISetup SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. 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