Jump to content

(solved) Need help with Listwiev


Borje
 Share

Recommended Posts

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 by Borje
Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

OK here is the most simple way

#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

 

Link to comment
Share on other sites

  • Borje changed the title to (solved) Need help with Listwiev

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...