Borje Posted September 29, 2022 Posted September 29, 2022 (edited) Hi everybody I need some help I can not figure it out how fix to add a new user into this listwiev and also a save button to save the new info to the test.txt file? Please if anybody could help me with this. Please see the attaced files. ; AutoIt 3.3.12.0 #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> GUICreate("Listwiew", 300, 230) Local $idSelBtn = GUICtrlCreateButton('Select', 10, 05, 40, 20) Local $idListview = GUICtrlCreateListView("Name|Location|Email Address", 10, 30, 280, 180, $LVS_SORTDESCENDING) _GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE_USEHEADER) ; listview from text file...columns are "|" delimited Local $aTextFile = StringSplit(FileRead(@ScriptDir & '\test.txt'), @CRLF, $STR_ENTIRESPLIT) For $i = 1 To $aTextFile[0] If $aTextFile[$i] = '' Then ContinueLoop GUICtrlCreateListViewItem($aTextFile[$i], $idListview) Next GUISetState(@SW_SHOW) Local $aIndices, $out While 1 Switch GUIGetMsg() Case $idSelBtn ; get # of listview rows selected $aIndices = _GUICtrlListView_GetSelectedIndices($idListview, True) $out = '' ; loop thru selected indicies and format out For $i = 1 To $aIndices[0] $out &= _GUICtrlListView_GetItemText($idListview, $aIndices[$i],0) & @TAB $out &= _GUICtrlListView_GetItemText($idListview, $aIndices[$i],2) & @CRLF Next MsgBox(0, 'Email Selection', $out) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Listwiev.zip Edited September 30, 2022 by Borje
mikell Posted September 29, 2022 Posted September 29, 2022 3 hours ago, Borje said: I can not figure it out how fix to add a new user I can see nothing about this in your code. What did you try ? Where are the inputs to enter names and emails, buttons, and so on ? BTW since 2007 you still don't know how to use the <code> tag ?
Borje Posted September 29, 2022 Author Posted September 29, 2022 I remove this from the code as is not worked and yes I know how to tag the code today I forget to tag the code Iam so sorry, but is that anybody here than can help me how to do and give me example on add and how save?
mikell Posted September 30, 2022 Posted September 30, 2022 OK here is the most simple way expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <StringConstants.au3> $file = @ScriptDir & '\test.txt' GUICreate("Listwiew", 300, 230) Local $idListview = GUICtrlCreateListView("Name|Location|Email Address", 10, 30, 280, 180, $LVS_SORTDESCENDING) _GUICtrlListView_SetColumnWidth($idListview, 2, $LVSCW_AUTOSIZE_USEHEADER) Local $idSelBtn = GUICtrlCreateButton('Select', 10, 05, 40, 20) $input_name = GUICtrlCreateInput("name", 80, 5, 50, 20) $input_location = GUICtrlCreateInput("location", 135, 5, 50, 20) $input_email = GUICtrlCreateInput("email", 190, 5, 50, 20) $button_add = GUICtrlCreateButton('Add', 250, 05, 30, 20) _FillListview() GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $button_add $new = GuiCtrlRead($input_name) & "|" & GuiCtrlRead($input_location) & "|" & GuiCtrlRead($input_email) If not StringInStr(FileRead($file), $new) Then ; avoid duplicates FileWrite($file, $new & @crlf) _GUICtrlListView_DeleteAllItems($idListview) _FillListview() EndIf Case $idSelBtn ; get # of listview rows selected $aIndices = _GUICtrlListView_GetSelectedIndices($idListview, True) $out = '' ; loop thru selected indicies and format out For $i = 1 To $aIndices[0] $out &= _GUICtrlListView_GetItemText($idListview, $aIndices[$i],0) & @TAB $out &= _GUICtrlListView_GetItemText($idListview, $aIndices[$i],2) & @CRLF Next MsgBox(0, 'Email Selection', $out) Case $GUI_EVENT_CLOSE GUIDelete() Exit EndSwitch WEnd Func _FillListview() Local $aTextFile = StringSplit(FileRead($file), @CRLF, $STR_ENTIRESPLIT) For $i = 1 To $aTextFile[0] If $aTextFile[$i] = '' Then ContinueLoop GUICtrlCreateListViewItem($aTextFile[$i], $idListview) Next EndFunc
Borje Posted September 30, 2022 Author Posted September 30, 2022 Hi mikell Than you very much for the help and the example code. I test this and it works perfect I must now look in the code and try to learn from it.
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