Jump to content

GUICtrlCreateListView


 Share

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>
#EndRegion
;
#region - :OPTIONS
Opt("GUIOnEventMode",1)
Opt("TrayMenuMode",1)
#endregion
;
#region - :GLOBALS
Global  $DEST       = "\\Server\Share\Directory to check"       ;Path to the Directory to check, no trailing backslash
Global  $MainGUI,$ListView
Global  $ButtonRun,$ButtonClose
#endregion
;
#region - :GUI CREATION
$MainGUI    = GUICreate("Title",825,420,10,10,-1,$WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE,'_ExitNow')

#region - :OUTPUT               - Display for status report
$ListView = GUICtrlCreateListView("DIRECTORY|DAYS OLD|STATUS", 7,222,804,145,BitOR($ES_READONLY,$LVS_SHOWSELALWAYS),BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT))
    _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)
#endregion

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

#region - :ON_EVENT_ACTIONS     - Action to take on Button Click
GUICtrlSetOnEvent($ButtonRun,'_RunNow')
GUICtrlSetOnEvent($ButtonClose,'_ExitNow')
#endregion

GUISetState(@SW_SHOW)
#endregion
;
#region - :LOOP
While 1
    Sleep(10)
WEnd
#endregion
;
#region - :EXIT
Func _ExitNow()
    Exit
EndFunc
#endregion
;
#region - :CHECK/REMOVE DIRECTORIES
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)
    _ArraySort($oDir)

    Local $dDir,$NewDate,$Output
    For $b = 1 To 20 ;$oDir[0]
        $dDir = "KEPT"
        If $oDir[$b] = "ProfileLoader" Then
        Else
            ;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
            EndIf
            ;Display the information in the ListView
            $Output = GUICtrlCreateListViewItem($oDir[$b] & "|" & $NewDate & "|" & $dDir,$ListView)
            GUICtrlSetData($ListView,$Output,1)

            ;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
            Sleep(100)
        EndIf
    Next
    MsgBox(262144,'Directory Cleaned','All old Directories have been removed')
    GUICtrlSetState($ButtonClose,$GUI_FOCUS)
EndFunc
#endregion
;

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...

Thanks,

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

Link to comment
Share on other sites

  • Moderators

Country73,

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)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
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

Link to comment
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
 Share

  • Recently Browsing   0 members

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