timdecker Posted April 14, 2015 Share Posted April 14, 2015 (edited) I am trying to clear my listview....which I can do, but when i try to load a new file into the listview, nothing happens. Here is the function I am trying to use: Func _loadNewFile() _GUICtrlListView_DeleteAllItems($listview) _FileReadToArray($selectFile,$a_csv) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) EndFunc And here is the entire code: expandcollapse popup#cs Solution to that is to move the window to the same screen location every time the program is run or the loop recycles. Or test to see if it's on the X/Y you want and if not, force it there. Use this as example for input box field when testing submition: http://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_legend #ce #include <file.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <GuiListView.au3> #include <Array.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> Global $a_csv Global $listview Global $checkboxName Global $iCount Global $runProg Global $acheck Global $mapColumn Global $runProg Global $selectInstrument Global $selectFile $s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)") If @error Then MsgBox(4096, "", "No File(s) chosen") Exit Else _FileReadToArray($s_Path, $a_csv) buildGUI() EndIf Func _loadNewFile() _GUICtrlListView_DeleteAllItems($listview) _FileListToArray($selectFile,$a_csv) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) EndFunc Func copyToInput() ;$title = "(METTLER) - TGA-200A with gas box" ;$title = "HPOV" Select Case GUICtrlRead($selectInstrument) = "dummy" $textPos = 4 $title = "HPOV" Case GUICtrlRead($selectInstrument) = "TGA-100" $textPos = 35 $title = "(METTLER) - TGA-100A with gas box" Case GUICtrlRead($selectInstrument) = "TGA-200" $textPos = 44 $title = "(METTLER) - TGA-200A with gas box" Case GUICtrlRead($selectInstrument) = "AUTOCAT-100" $textPos = 75 Case GUICtrlRead($selectInstrument) = "AUTOCAT-200" $textPos = 15 EndSelect $allRows = _GUICtrlListView_GetItemCount($listview) For $rows = 0 to $allRows-1 $material_name = _GUICtrlListView_GetItem($listview, $rows, 0) $letter = _GUICtrlListView_GetItem($listview, $rows, 3) ;where to input if statement so only checkbox that is checked runs???? If GUICtrlRead($aCheck[1]) <> 1 and GUICtrlRead($aCheck[4]) <> 1 then continueloop If GUICtrlRead($aCheck[1]) = 1 Then controlsettext($title, "", $textPos, $material_name[3]) endif #cs - 2nd input box If GUICtrlRead($aCheck[4]) = 1 Then controlsettext($title, "", 5, $letter[3]) endif #ce controlclick($title, "", 6) Sleep(2000) ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads controlclick("Job", "", 2) Sleep(2000) ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads if msgbox(1,"", "You Shall Not Pass!" & @CRLF & "Ok actually you can, just press something") = 2 then ExitLoop endif Next EndFunc Func buildGUI() GUICreate("CSV Listview", 900, 450, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) GUICtrlCreateLabel("Select a sample file:", 450, 40, 200) $selectFile = GUICtrlCreateCombo("", 450, 60, 180, 200) ;GUICtrlSetData($selectFile, @ScriptDir & '\*.csv') _GUICtrlComboBox_BeginUpdate($selectFile) _GUICtrlComboBox_AddDir($selectFile, @ScriptDir & "\*.csv") _GUICtrlComboBox_EndUpdate($selectFile) ;GUISetState(@SW_SHOW) $loadNewFile = GUICtrlCreateButton("Load File", 450, 80) GUICtrlCreateLabel("Select an instrument:", 700, 40, 200) $selectInstrument = GUICtrlCreateCombo("", 700, 60, 180, 25) GUICtrlSetData(-1, "dummy|TGA-100|TGA-200|AUTOCAT-100|AUTOCAT-200") $checkboxName = StringSplit($a_csv[1], ",") $iCount = $checkboxName[0] ;creating buttons Global $aCheck[$iCount + 1] Global $mapColumn[$iCount + 1] ;$nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30) $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30) GUICtrlSetState($runProg, $GUI_DISABLE) ;$btnStop = GUICtrlCreateButton("Stop", 700, 400, 180, 30) For $j = 1 To $iCount ; Store controIDs of the checkboxes $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30) ; $mapColumn[$j] = GUICtrlCreateButton("Map " & '"' & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30) GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED) ; GUICtrlSetState($mapColumn[$j], $GUI_DISABLE) Next For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next Global $aOut[''][''] For $i = 2 to $a_csv[0] $aLine = stringsplit($a_csv[$i] , ",",3) If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)] _ArrayAdd($aOut , $a_csv[$i] , 0 , ",") ;consolewrite("line: " & $aLine[2] & @LF) Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $runProg copyToInput() Case $loadNewFile _loadNewFile() ;_FileReadToArray($selectFile,$a_csv) Case Else For $i = 1 To $iCount If $msg = $aCheck[$i] Then If GUICtrlRead($msg) = 1 Then ; GUICtrlSetState($mapColumn[$i], $GUI_ENABLE) GUICtrlSetState($runProg, $GUI_ENABLE) ; ; Local $text = "" ; For $k = 0 to $a_csv[0]-1 ; $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf ; ; Next ;Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected Else ;GUICtrlSetState($mapColumn[$i], $GUI_DISABLE) GUICtrlSetState($runProg, $GUI_DISABLE) EndIf ExitLoop EndIf Next EndSwitch WEnd EndFunc What am I doing wrong? Thanks, Tim Edited April 14, 2015 by timdecker Link to comment Share on other sites More sharing options...
timdecker Posted April 14, 2015 Author Share Posted April 14, 2015 (edited) I can do something like this: Func _loadNewFile() _GUICtrlListView_DeleteAllItems($listview) _FileReadToArray(GUICtrlRead($selectFile),$a_csv) ;$listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) buildGUI() EndFunc It will load the file in a new windows....but I don't want to have to create a new window every time. How do I just load it in the current window??? On top of that, if I use this code: Func _loadNewFile() _GUICtrlListView_DeleteAllItems($listview) _FileReadToArray(GUICtrlRead($selectFile),$a_csv) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) ;buildGUI() EndFunc All it does is change the headers.... Edited April 14, 2015 by timdecker Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 14, 2015 Moderators Share Posted April 14, 2015 (edited) You're trying to repopulate an existing listview, right? In your function you're calling GuiCtrlCreateListView, instead of GuiCtrlCreateListViewItem. Take a look at this reproducer: #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> GUICreate("Test", 300, 300) $sListView = GUICtrlCreateListView("col1|col2", 10, 10, 280, 180) For $i = 1 To 20 GUICtrlCreateListViewItem($i & "|" & $i * 10, $sListView) Next $sButton = GUICtrlCreateButton("Go", 10, 200, 40, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $sButton _loadNewFile() EndSwitch WEnd GUIDelete() Func _loadNewFile() _GUICtrlListView_DeleteAllItems($sListView) Local $aArray = FileReadToArray(@DesktopDir & "\Test.txt") For $element In ($aArray) GUICtrlCreateListViewItem($element & "|" & $element, $sListView) Next EndFunc  Edited April 14, 2015 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
MikahS Posted April 14, 2015 Share Posted April 14, 2015 (edited) Try with _GUICtrlListView_AddArray Edit: this deals with a 2d array I just realized. Edited April 14, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Forum FAQ Â Link to comment Share on other sites More sharing options...
kylomas Posted April 14, 2015 Share Posted April 14, 2015 Hi Tim, In your BuildGui routine you are populating the listview correctly. Just do the same thing in your LoadNewFile routine. Very similar to what JL posted. 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...
timdecker Posted April 14, 2015 Author Share Posted April 14, 2015 (edited) You're trying to repopulate an existing listview, right? In your function you're calling GuiCtrlCreateListView, instead of GuiCtrlCreateListViewItem. Take a look at this reproducer: #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> GUICreate("Test", 300, 300) $sListView = GUICtrlCreateListView("col1|col2", 10, 10, 280, 180) For $i = 1 To 20 GUICtrlCreateListViewItem($i & "|" & $i * 10, $sListView) Next $sButton = GUICtrlCreateButton("Go", 10, 200, 40, 40) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $sButton _loadNewFile() EndSwitch WEnd GUIDelete() Func _loadNewFile() _GUICtrlListView_DeleteAllItems($sListView) Local $aArray = FileReadToArray(@DesktopDir & "\Test.txt") For $element In ($aArray) GUICtrlCreateListViewItem($element & "|" & $element, $sListView) Next EndFunc   That worked fairly well, the files loaded correctly, but the headers do not change, and they are not being seperated into the correct columns. It seems it is loading all the comma seperated data twice...once in to two columns. This is what the function is now: EDIT: I change the delimiter to "," and I have the same problem as above, except now just throwing everything in to one column. Func _loadNewFile() _GUICtrlListView_DeleteAllItems($ListView) Local $aArray = FileReadToArray(GUICtrlRead($selectFile)) For $a = 1 To UBound($aArray) - 1 GUICtrlCreateListViewItem($aArray[$a] & "," & $aArray[$a], $ListView) Next EndFunc Edited April 14, 2015 by timdecker Link to comment Share on other sites More sharing options...
timdecker Posted April 14, 2015 Author Share Posted April 14, 2015 (edited) I figured it out...or at least it is working now. Here is the function I need: Func _loadNewFile() _FileReadToArray(GUICtrlRead($selectFile),$a_csv) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next EndFunc Full Code: expandcollapse popup#include <file.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <GuiListView.au3> #include <Array.au3> #include <ComboConstants.au3> #include <GuiComboBox.au3> Global $a_csv Global $listview Global $checkboxName Global $iCount Global $runProg Global $acheck Global $mapColumn Global $runProg Global $selectInstrument Global $selectFile Global $s_Path $s_Path = FileOpenDialog("Select CVS File", @ScriptDir, "comma seperated values (*.csv)") If @error Then MsgBox(4096, "", "No File(s) chosen") Exit Else _FileReadToArray($s_Path, $a_csv) buildGUI() EndIf Func _loadNewFile() _FileReadToArray(GUICtrlRead($selectFile),$a_csv) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) Next EndFunc Func copyToInput() ;$title = "(METTLER) - TGA-200A with gas box" ;$title = "HPOV" Select Case GUICtrlRead($selectInstrument) = "dummy" $textPos = 4 $title = "HPOV" Case GUICtrlRead($selectInstrument) = "TGA-100" $textPos = 35 $title = "(METTLER) - TGA-100A with gas box" Case GUICtrlRead($selectInstrument) = "TGA-200" $textPos = 44 $title = "(METTLER) - TGA-200A with gas box" Case GUICtrlRead($selectInstrument) = "AUTOCAT-100" $textPos = 75 Case GUICtrlRead($selectInstrument) = "AUTOCAT-200" $textPos = 15 EndSelect $allRows = _GUICtrlListView_GetItemCount($listview) For $rows = 0 to $allRows-1 $material_name = _GUICtrlListView_GetItem($listview, $rows, 0) $letter = _GUICtrlListView_GetItem($listview, $rows, 3) ;where to input if statement so only checkbox that is checked runs???? If GUICtrlRead($aCheck[1]) <> 1 and GUICtrlRead($aCheck[4]) <> 1 then continueloop If GUICtrlRead($aCheck[1]) = 1 Then controlsettext($title, "", $textPos, $material_name[3]) endif #cs - 2nd input box If GUICtrlRead($aCheck[4]) = 1 Then controlsettext($title, "", 5, $letter[3]) endif #ce controlclick($title, "", 6) Sleep(2000) ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads controlclick("Job", "", 2) Sleep(2000) ;there you can put some sleep(5000) = 5seconds, more or less, if u know exact applications processing time for this operation ;or ControlGetText("Myapplication title", "", CONTROL_WHICH_CHANGES_AFTER_BUTTONPRESS) and compare to older reads if msgbox(1,"", "You Shall Not Pass!" & @CRLF & "Ok actually you can, just press something") = 2 then ExitLoop endif Next EndFunc Func buildGUI() GUICreate("CSV Listview", 900, 450, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_csv[1], ",", "|"), 10, 10, 400, 210) GUICtrlCreateLabel("Select a sample file:", 450, 40, 200) $selectFile = GUICtrlCreateCombo("", 450, 60, 180, 200) ;GUICtrlSetData($selectFile, @ScriptDir & '\*.csv') _GUICtrlComboBox_BeginUpdate($selectFile) _GUICtrlComboBox_AddDir($selectFile, @ScriptDir & "\*.csv") _GUICtrlComboBox_EndUpdate($selectFile) ;GUISetState(@SW_SHOW) $loadNewFile = GUICtrlCreateButton("Load File", 450, 80) GUICtrlCreateLabel("Select an instrument:", 700, 40, 200) $selectInstrument = GUICtrlCreateCombo("", 700, 60, 180, 25) GUICtrlSetData(-1, "dummy|TGA-100|TGA-200|AUTOCAT-100|AUTOCAT-200") $checkboxName = StringSplit($a_csv[1], ",") $iCount = $checkboxName[0] ;creating buttons Global $aCheck[$iCount + 1] Global $mapColumn[$iCount + 1] ;$nextSample = GUICtrlCreateButton("Map sample submition button ", 395, 320, 180, 30) $runProg = GUICtrlCreateButton("Run Program", 700, 400, 180, 30) GUICtrlSetState($runProg, $GUI_DISABLE) ;$btnStop = GUICtrlCreateButton("Stop", 700, 400, 180, 30) For $j = 1 To $iCount ; Store controIDs of the checkboxes $aCheck[$j] = GUICtrlCreateCheckbox($checkboxName[$j], 10, 190 + (50 * $j), 100, 30) ; $mapColumn[$j] = GUICtrlCreateButton("Map " & '"' & $checkboxName[$j] & '"' & " to input box", 150, 190 + (50 * $j), 180, 30) GUICtrlSetState($aCheck[$j], $GUI_UNCHECKED) ; GUICtrlSetState($mapColumn[$j], $GUI_DISABLE) Next For $i = 2 To UBound($a_csv) - 1 $s_temp = StringReplace($a_csv[$i], ",", "|") GUICtrlCreateListViewItem($s_temp, $listview) ;ConsoleWrite($s_temp) Next Global $aOut[''][''] For $i = 2 to $a_csv[0] $aLine = stringsplit($a_csv[$i] , ",",3) If ubound($aLine) > ubound($aOut , 2) Then redim $aOut[$i][ubound($aLine)] _ArrayAdd($aOut , $a_csv[$i] , 0 , ",") ; consolewrite("line: " & $aLine[2] & @LF) Next GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit Case $runProg copyToInput() Case $loadNewFile _GUICtrlListView_DeleteAllItems($listview) _loadNewFile() ;_FileReadToArray($selectFile,$a_csv) Case Else For $i = 1 To $iCount If $msg = $aCheck[$i] Then If GUICtrlRead($msg) = 1 Then ; GUICtrlSetState($mapColumn[$i], $GUI_ENABLE) GUICtrlSetState($runProg, $GUI_ENABLE) ; ; Local $text = "" ; For $k = 0 to $a_csv[0]-1 ; $text &= ControlListView ("CSV Listview", "", $listview, "GetText", $k, $i-1) & @crlf ; ; Next ;Msgbox(0,$checkboxName[$i], $text) ; debug, can see the list of samples you selected Else ;GUICtrlSetState($mapColumn[$i], $GUI_DISABLE) GUICtrlSetState($runProg, $GUI_DISABLE) EndIf ExitLoop EndIf Next EndSwitch WEnd EndFunc Thanks for sticking in there with me everyone! Tim EDIT: DAMNIT THE CHECKBOXES ARE NOT UPDATING IF IT IS A DIFFERENT FILE! Edited April 14, 2015 by timdecker 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