sleepydvdr Posted October 27, 2011 Share Posted October 27, 2011 I am attempting to write some code to possibly help someone else on this board. However, I cannot figure out something. I have a list view that I'm trying to refresh. My idea is to delete the listview, recreate it and re-populate the data every time something is added, changed or deleted. The _RefreshData() function deletes it, but does not re-create it. Currently, only the Add A Product button has been written. Does anyone have any explanation why this is happening. I don't understand it. Here is my code: expandcollapse popup#include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <array.au3> Global $productCode,$make,$model,$currentStock,$dataModified IniWrite("InventoryData.ini", "test", "test", "1") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 442, 192, 124) $ListView1 = GUICtrlCreateDummy() ; Created a dummy to avoid an error on first run of the _RefreshData() function $Button1 = GUICtrlCreateButton("Add A Product", 16, 408, 91, 25) $Button2 = GUICtrlCreateButton("Edit A Product", 120, 408, 91, 25) $Button3 = GUICtrlCreateButton("Delete A Product", 224, 408, 107, 25) GUISetState(@SW_SHOW) _RefreshData() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _AddAProduct() EndSwitch WEnd Func _AddAProduct() #Region ### START Koda GUI section ### Form= $Form2 = GUICreate("Form1", 336, 258, 302, 218) $cInput1 = GUICtrlCreateInput("", 16, 24, 193, 21) $cInput2 = GUICtrlCreateInput("", 16, 64, 193, 21) $cInput3 = GUICtrlCreateInput("", 16, 104, 193, 21) $cInput4 = GUICtrlCreateInput("", 16, 144, 193, 21) $cInput5 = GUICtrlCreateInput("", 16, 184, 193, 21) $Label1 = GUICtrlCreateLabel("Product Code", 224, 24, 69, 17) $Label2 = GUICtrlCreateLabel("Make", 224, 64, 31, 17) $Label3 = GUICtrlCreateLabel("Model", 224, 104, 33, 17) $Label4 = GUICtrlCreateLabel("Current Stock", 224, 144, 69, 17) $Label5 = GUICtrlCreateLabel("Date Modified", 224, 184, 70, 17) $Button3 = GUICtrlCreateButton("Add Product", 120, 216, 91, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete($Form2) ExitLoop Case $Button3 $productCode = GUICtrlRead($cInput1) $make = GUICtrlRead($cInput2) $model = GUICtrlRead($cInput3) $currentStock = GUICtrlRead($cInput4) $dataModified = GUICtrlRead($cInput5) $errorCheck = IniRead("InventoryData.ini", "Product Code", "Product Code", "NotInDatabase") If $errorCheck = "NotInDatabase" Then IniWrite("InventoryData.ini", $productCode, "Product Code", $productCode) IniWrite("InventoryData.ini", $productCode, "Make", $make) IniWrite("InventoryData.ini", $productCode, "Model", $model) IniWrite("InventoryData.ini", $productCode, "Current Stock", $currentStock) IniWrite("InventoryData.ini", $productCode, "Date Modified", $dataModified) Else MsgBox(0, "Error", "The product is already in the database") EndIf _RefreshData() GUIDelete($Form2) ExitLoop EndSwitch WEnd EndFunc Func _RefreshData() GUICtrlDelete($ListView1) ; Delete the old listview $ListView1 = GUICtrlCreateListView("Product Code|Make|Model|Current Stock|Date Modified", 16, 8, 586, 390) ; Re-create the listview GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 85) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 100) $sectionNames = IniReadSectionNames("InventoryData.ini") For $i = 1 to $sectionNames[0] Step 1 $productCode = IniRead("InventoryData.ini", $sectionNames[$i], "Product Code", "NotFound") $make = IniRead("InventoryData.ini", $sectionNames[$i], "Make", "NotFound") $model = IniRead("InventoryData.ini", $sectionNames[$i], "Model", "NotFound") $currentStock = IniRead("InventoryData.ini", $sectionNames[$i], "Current Stock", "NotFound") $dataModified = IniRead("InventoryData.ini", $sectionNames[$i], "Date Modified", "NotFound") GUICtrlCreateListViewItem($productCode & "|" & $make & "|" & $model & "|" & $currentStock & "|" & $dataModified, $ListView1) Next EndFunc #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
enaiman Posted October 27, 2011 Share Posted October 27, 2011 (edited) I am not sure 100% but for me it seems that your script will create the listview in the GUI you are deleting the very next line. Try deleting the $Form2 before running _RefreshData When working with multiple GUIs, take care to have the correct GUI selected. Use GUISwitch. If deleting the GUI first does not work - use GUISwitch($Form1) before running _RefreshData Edited October 27, 2011 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
sleepydvdr Posted October 27, 2011 Author Share Posted October 27, 2011 (edited) enaiman, your suggestion of GuiSwitch fixed the problem! Thank you! Now I can proceed. I encountered the same problem in another project I worked on and now I can fix that one, too. Thanks again for your help! Just for information purposes, this is a link to the thread I'm trying to help: Edited October 27, 2011 by sleepydvdr #include <ByteMe.au3> 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