Highlight next file in list after deletion
Posted: Wednesday 9th May 2018 11:03am
I find it annoying when working through a list of files in a FileChooser, that when I delete one, I lose my place. I want the FileChooser to highlight the next file following the deleted one.
Recently, when building my BatCallSorter, I fixed this issue in my code by finding the name of the next file in the list...
The code above just needs a Form, a FileChooser and a Button control.
Recently, when building my BatCallSorter, I fixed this issue in my code by finding the name of the next file in the list...
Public Function GetNextFile(strFile2Delete As String) As String
'look for current selected file and return the next one (if there is a next one!)
Dim strFileName As String
Dim iCount As Integer
Dim blnMatch As Boolean
For Each strFileName In Dir(FileChooser1.Dir, "*", gb.File).Sort()
Inc iCount
If blnMatch Then
Return strFileName 'next file in list
Endif
If strFile2Delete = FileChooser1.Dir & "/" & strFileName And FileChooser1.FileView.Count > iCount Then
blnMatch = True
Endif
Next
Return "" 'no match or no more files
End
...then deleting the current file, and selecting the next file.
Public Sub btnDelete_Click()
'Delete currently selected file and load the next file
Dim lngReply As Long
Dim strSelectNextFile As String
If FileChooser1.SelectedPath = "" Then
Message.Warning("You didn't select a file for deletion!", "close")
Else
lngReply = Message.Question("Are you sure you want to delete: " & FileChooser1.FileView.Current & "?", "Yes", "No")
If lngReply = 1 Then
strSelectNextFile = GetNextFile(FileChooser1.SelectedPath)
Try Kill FileChooser1.SelectedPath
If Not Error Then
FileChooser1.FileView.Current = strSelectNextFile
Endif
Endif
Endif
FileChooser1.FileView.Reload
FileChooser1.FileView.SetFocus
End
If there is a easier (less code) way of doing this, please let me know.The code above just needs a Form, a FileChooser and a Button control.