Jump to content
Sign in to follow this  


Recommended Posts


I'm working on a small GUI that uses a ListView to show the current state of my program.

Purpose of the GUI is to check the date on a folder then display KEEP or DELETE determined by the age of the Directory.

Everything seems to be working fine, except that I need the new item to be highlighted and visible in the ListView.

I know I've worked through this before, but I can't locate one of my old scripts that this was in.

I've also been searching through the forum, but just haven't been able to locate what I'm looking for.

(This GUI performs more functions, but I've slimmed it down to just the problem I'm working on)

#Region     ;Includes   - Additional Scripts to perform specific functions in main script
#include <Array.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <Date.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIConstantsEX.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#region - :OPTIONS
#region - :GLOBALS
Global  $DEST       = "\\Server\Share\Directory to check"       ;Path to the Directory to check, no trailing backslash
Global  $MainGUI,$ListView
Global  $ButtonRun,$ButtonClose
#region - :GUI CREATION
$MainGUI    = GUICreate("Title",825,420,10,10,-1,$WS_EX_TOPMOST)

#region - :OUTPUT               - Display for status report
    _GUICtrlListView_SetColumnWidth($ListView, 0, 133)
    _GUICtrlListView_SetColumnWidth($ListView, 1, 133)
    _GUICtrlListView_SetColumnWidth($ListView, 2, 133)
    _GUICtrlListView_SetColumnWidth($ListView, 3, 133)
    _GUICtrlListView_SetColumnWidth($ListView, 4, 133)
    _GUICtrlListView_SetColumnWidth($ListView, 5, 133)

#region - :BUTTONS          - Interaction by user
$ButtonRun      = GUICtrlCreateButton("RUN",10,380,91,33,$BS_CENTER)
$ButtonClose    = GUICtrlCreateButton("EXIT",105,380,91,33,$BS_CENTER)

#region - :ON_EVENT_ACTIONS     - Action to take on Button Click

#region - :LOOP
While 1
#region - :EXIT
Func _ExitNow()
Func _RunNow()
    ;Set value on Juliandate for today, Round for no decimal place
    Local $sJulDate = Round(_DateToDayValue(@YEAR,@MON,@MDAY))
    Local $oDir = _FileListToArray($DEST,'*',2)

    Local $dDir,$NewDate,$Output
    For $b = 1 To 20 ;$oDir[0]
        $dDir = "KEPT"
        If $oDir[$b] = "ProfileLoader" Then
            ;Get Date of the Directory, then switch it to Juliandate
            Local $DirCreateDate = FileGetTime($DEST & "\" & $oDir[$b])
            Local $DirJulDate = Round(_DateToDayValue($DirCreateDate[0],$DirCreateDate[1],$DirCreateDate[2]))
            $NewDate = ($sJulDate - $DirJulDate) ;Subtract Today by DirCreation Date
            ;Check if older than 14 days
            If $NewDate > 14 Then
                $dDir = "DELETED"
                ;This is where I would put in the "DirRemove" command
            ;Display the information in the ListView
            $Output = GUICtrlCreateListViewItem($oDir[$b] & "|" & $NewDate & "|" & $dDir,$ListView)

            ;HERE is where I need the focus on the last item entered into the ListView

            ;Since this isn't actually Deleting any directories, slight pause between checks
    MsgBox(262144,'Directory Cleaned','All old Directories have been removed')

Any pointers/commands I should be looking into?

I've tried GUICtrlSetState, pretty much all of the _GuiCtrlListView_, but I could just be using them wrong.

Long week, frustrated, and probably just not thinking straight...


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post

Link to post
Share on other sites


Try this - it works for me: :(

;HERE is where I need the focus on the last item entered into the ListView
_GUICtrlListView_EnsureVisible($ListView, $b - 1)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

@ Melba23

Thanks, that works.

I looked over the commands I tried previously, and I had tried that one. I just had it written wrong...

My Attempt: (wrong) _GuiCtrlListView_EnsureVisible($ListView, $b )

Correct: _GuiCtrlListView_EnsureVisible($ListView, $b - 1 )

That " - 1 " was the key I was missing...

Thanks for helping me locate what I overlooked!

If you try to fail and succeed which have you done?AutoIt Forum Search

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