Jump to content
Sign in to follow this  
JohnBailey

ListView using an External File

Recommended Posts

Zedna and xcal, thank you both for those leads and explanations. I really don't like not understanding what I'm writing!

Now I'm trying to save the change I made to that row.

I did the following, but it puts the changed entry at the bottom:

If $msg = $btnSaveEdits Then
        $selected = _GUICtrlListViewGetCurSel($list)
        _GUICtrlListViewSetItemText($list,$selected,0,GUICtrlRead($editAccountName))
        _GUICtrlListViewSetItemText($list,$selected,1,GUICtrlRead($editAccountNumber))
        _GUICtrlListViewSetItemText($list,$selected,2,GUICtrlRead($editAccountFile))
        _GUICtrlListViewSetItemText($list,$selected,3,GUICtrlRead($editDate))
        $file = FileOpen($dataBaseActivity, 1)
        _ArrayDelete($array, 0)
        $new = GUICtrlRead($editAccountName) & " * " & GUICtrlRead($editAccountNumber)& " * " & GUICtrlRead($editAccountFile) & " * " &  GUICtrlRead($editDate)
        _ArrayPush($array,$new)
        $write = _FileWriteFromArray($dataBaseActivity,$array,0)
        FileClose($file)
        _GUICtrlListViewDeleteAllItems ($list)
        GUICtrlSetData($inputAccountName,"")
        GUICtrlSetData($inputAccountNumber,"")
        GUICtrlSetData($inputAccountFile,"")
        list()
    EndIf
Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites

#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <Array.au3>

Global Const $WM_NOTIFY = 0x004E
Global Const $NM_FIRST = 0
Global Const $NM_CLICK = ($NM_FIRST - 2)

GUICreate('listview', 220, 234)

$list = GUICtrlCreateListView('column 1|column 2', 10, 10, 200, 150)
GUICtrlCreateListViewItem('column 1 item 1|column 2 item 1', $list)
GUICtrlCreateListViewItem('column 1 item 2|column 2 item 2', $list)
GUICtrlCreateListViewItem('column 1 item 3|column 2 item 3', $list)

_GUICtrlListViewSetColumnWidth($list, 0, 98)
_GUICtrlListViewSetColumnWidth($list, 1, 98)

$input1 = GUICtrlCreateInput('', 10, 170, 95, 20)
$input2 = GUICtrlCreateInput('', 115, 170, 95, 20)

$btn1 = GUICtrlCreateButton('Change Selected', 10, 200, 95, 24)
$btn2 = GUICtrlCreateButton('Save List', 115, 200, 95, 24)

GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn1
            $selected = _GUICtrlListViewGetCurSel($list)
            _GUICtrlListViewSetItemText($list, $selected, 0, GUICtrlRead($input1))
            _GUICtrlListViewSetItemText($list, $selected, 1, GUICtrlRead($input2))
        Case $btn2
            Local $list_count = _GUICtrlListViewGetItemCount($list)
            Local $array[1] = [$list_count]
            For $i = 1 To $list_count
                $replace = StringReplace(_GUICtrlListViewGetItemText($list, $i - 1), '|', ' * ')
                _ArrayAdd($array, $replace)
            Next
            _ArrayDisplay($array, 'Write to a file...')
    EndSwitch
WEnd

Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
        Case $wParam = $list
            Select
                Case $event = $NM_CLICK
                    $seltxt = StringSplit(_GUICtrlListViewGetItemText($list), '|')
                    If UBound($seltxt) - 1 = 2 Then
                        GUICtrlSetData($input1, $seltxt[1])
                        GUICtrlSetData($input2, $seltxt[2])
                    EndIf
            EndSelect
    EndSelect
    $tagNMHDR = 0
    $event = 0
    $lParam = 0
    Return $GUI_RUNDEFMSG
EndFunc

Edit - Btw, there are probably people cringing for me handing over direct answers (maybe?) but I'm bored, so I don't mind.

Edited by xcal

Share this post


Link to post
Share on other sites

xcal HAHA Well I really appreciate it because I'm learning a TON! Good call on the StringReplace! Today has actually been so very enlightening in regards to AutoIt and the way my script logic is formed. So, some may cringe at you giving me answers, but rest assured. You're teaching this man to fish. I'm reading the tech docs like crazy because I don't want to just write this stuff out! I want to understand how it works and what I mean by what I write! When I see something new to me, I hit the tech docs and this forum. Thanks again xcal for all your help!


A decision is a powerful thing

Share this post


Link to post
Share on other sites

xcal, I know this was awhile ago (thanks again BTW what I learned and what you instructed me specifically to do helped a ton!).

I was looking through the script again and I'm fuzzy on a few parts. I've reread and tested several times the manual, yet I'm still in an unclear understanding.

1. What does the following mean. I understand that $var = [$numbervar] sets a var to an array, but I don't understand what

Local $array[1] = [$list_count]

means since it's using $array[1]<--- the number and brackets before equaling.

2. According to the manual, _ArrayAdd only adds an element to the end of an array. However, the script you showed me actually changes the selected element! Freaking awesome, but how?

Again thanks as always!!

(this is really just me wanting to really understand this stuff. I'm not having any problems with it. Just curious) :whistle:

Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites

It sets the elements of the array.

Declare the array:

Local $array[1]oÝ÷ ØÚ0Â+auç%j¸§+p{ozÚ%vØ^{^®Þµêí«méÅé^éíw^Æ+5ÂgÌq©è¡j÷½©ny«tz
YmëÚçºÚ"µÍØØ[  ÌÍØ^VÌWHHÉÌÍÛÝØÛÝ[

We would have told the interpreter that we have 2 elements in this array ([0] and [1])

And [0] would be empty, and [1] would hold the value contained in $list_count


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

I think I'm understanding part 2 now.

_GUICtrlListViewSetItemText($list, $selected, 0, GUICtrlRead($editAccountName))

_GUICtrlListViewSetItemText($list, $selected, 1, GUICtrlRead($editAccountNumber))

_GUICtrlListViewSetItemText($list, $selected, 2, GUICtrlRead($editAccountFile))

_GUICtrlListViewSetItemText($list, $selected, 3, GUICtrlRead($editDate))

Local $list_count = _GUICtrlListViewGetItemCount($list)

Local $array[1] = [$list_count]

For $i = 1 To $list_count

$replace = StringReplace(_GUICtrlListViewGetItemText($list, $i - 1), '|', ' * ')

_ArrayAdd($array, $replace)

Next

$write = _FileWriteFromArray($dbChoice, $array, 1)

The _GUICtrlListViewSetItemText is changing the text of the currently selected listview item and then it's going through the entire listview and saving that back out to the file


A decision is a powerful thing

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×
×
  • Create New...