Table of Contents

6.9.4 FileView

The FileView (gb.form) control displays files in a selected directory.

A FileView control can be created:

Dim hFileView As FileView

hFileView = New FileView ( Parent As Container ) As "EventName"

6.9.4.1 Properties

The FileView class has these properties:

PropertyData typeDescription
BackgroundIntegerReturns the background colour or sets this colour.
BorderBooleanIndicates whether a border is set (default) or removes an existing border with the value 'False'.
CountIntegerReturns the number of files in the current directory (FileView.Dir) of the FileView. An inserted filter changes this number.
CurrentStringReturns the name of the selected file or selects the specified file in the current directory.
DirStringReturns the current directory in the FileView or sets the current directory of the FileView.
FilterString[ ]Returns the filters used by the control in a string array or sets them to show only certain file types. Each filter is a file pattern with wildcards. File names are matched with the LIKE command.
ForegroundIntegerReturns or sets the colour of the filenames.
IconPictureReturns or sets the icon for displaying a file or directory. Use this property to respond to the icon event.
IconSizeIntegerReturns or sets the icon size used by the view. The default value is 32.
ModeIntegerReturns or sets the FileView selection mode. The value of this property can be one of the constants (Multiple, None or Single) of the class Select (gb.qt4).
Selection String[ ]Returns the list of selected files in a string array if the property FileView.Mode is set to Select.Multiple.
Settings Variant[ ]Returns or assigns the configuration of the FileView. The configuration is stored in a Variant array in an unspecified format. Note: Since the Settings property serves as an interface to the gb.settings component, which allows graphical controls to serialise and re-read their own state, you should refrain from using this property.
ShowDetailedBooleanIndicates whether the files in the FileView are displayed with a detailed view or only with icons and the file names or sets the display of the detailed view.
ShowDirectoryBooleanIndicates whether the control also shows directories or not or sets the display of the directories.
ShowHiddenBooleanIndicates whether the control also shows hidden files or not or sets the display of hidden files.
ShowPreviewBooleanIndicates whether or not the control shows thumbnails for image files or sets the display of thumbnails of image files.

Table 6.9.4.1.1 : Properties of the FileView class.

Notes:

B1
Figure 6.9.4.1.1: Selected file in a FileView

B2
Figure 6.9.4.1.2: List of selected files in a FileView

6.9.4.2 Methods

The FileView class has these selected methods:

MethodDescription
Reload( )Updates the contents of the FileView by re-reading the current directory.
Rename( )Starts renaming the currently selected file.
SelectAll( )Selects all entries in the FileView.
UnselectAll( )Resets all selected entries in the FileView.

Table 6.9.4.2.1 : Selected methods of the FileView class

6.9.4.3 Events

The FileView class has the following events, among others:

EventDescription
Activate( )This event is triggered when a user double-clicks on a file.
Click( )This event is triggered when a user clicks on a file. The event also triggers the select event first!
Icon( Path As String )This event is triggered when the control needs to get the icon for a specific file or directory. Path is the image path.
Menu( )This event is triggered when the user invokes a pop-up menu.
Select( )This event is triggered when a user only selects a file (MouseLeft_Down).

Table 6.9.4.3.1 : Events of the FileView class

6.9.4.4 Project

The source code for the project implements the above notes:

' Gambas class file
 
Public sFileName As String
Public aFileNames As String[]
 
Public Sub Form_Open()
 
  FMain.Resizable = False
  DirBox1.Value = "/home/hans/BildTon" ' (Start-)Folder
 
  FileView1.Dir = DirBox1.Value
  FileView1.IconSize = 32 ' Default-Value = 32
  FileView1.ShowPreview = True
  FileView1.ShowHidden = True
  FileView1.Background = &HC3DDFF
  FileView1.Foreground = Color.DarkGreen
  FileView1.Mode = Select.Single
 
  FileView1.Filter = ["*.txt", "*.png", "*.pd*", "*.jp*", "*.xml"]
  Wait
 
  btnShowFileListContent.Enabled = False
 
End
 
Public Sub FileView1_Click()
 
  Dim sFileDir, sFilePath As String
 
  sFileName = FileView1.Current
  sFileDir = FileView1.Dir
  sFilePath = sFileDir &/ sFileName
 
  lblFileName.Text = Subst("&1 &2 &3", ("Filename"), ":", sFileName)
 
End
 
Public Sub FileView1_Select()
  If FileView1.Current Then
     Print Subst("&1 '&2' &3", ("The file"), FileView1.Current, ("has been selected."))
  Endif
End
 
Public Sub DirBox1_Click()
  FileView1.Dir = DirBox1.Value
End
 
Public Sub btnSetMultiple_Click()
 
  If FileView1.Mode = Select.Single Then ' The default-value is "Single"
     FileView1.Mode = Select.Multiple
     btnSetMultiple.Caption = "Set file selection to single"
     btnShowFileListContent.Enabled = True
  Else
     FileView1.Mode = Select.Single
     btnSetMultiple.Caption = "Set file selection to multiple"
     btnShowFileListContent.Enabled = False
  Endif
 
End
 
Public Sub btnShowFileListContent_Click()
 
  Dim sFile, sContent As String
 
  If FileView1.Mode = Select.Multiple Then
     If FileView1.Selection.Count > 0 Then
        lblFileName.Text = ""
        aFileNames = FileView1.Selection
        For Each sFile In aFileNames
          sContent &= sFile & gb.Lf
        Next
        Message.Info("Selected files:<hr>" & sContent)
        FileView1.UnselectAll()
        FileView1.Mode = Select.Single
        btnSetMultiple.Caption = "Set file selection to multiple"
        btnShowFileListContent.Enabled = False
     Endif
  Endif
End

Download

Project

Download