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"
The FileView class has these properties:
Property | Data type | Description |
---|---|---|
Background | Integer | Returns the background colour or sets this colour. |
Border | Boolean | Indicates whether a border is set (default) or removes an existing border with the value 'False'. |
Count | Integer | Returns the number of files in the current directory (FileView.Dir) of the FileView. An inserted filter changes this number. |
Current | String | Returns the name of the selected file or selects the specified file in the current directory. |
Dir | String | Returns the current directory in the FileView or sets the current directory of the FileView. |
Filter | String[ ] | 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. |
Foreground | Integer | Returns or sets the colour of the filenames. |
Icon | Picture | Returns or sets the icon for displaying a file or directory. Use this property to respond to the icon event. |
IconSize | Integer | Returns or sets the icon size used by the view. The default value is 32. |
Mode | Integer | Returns 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. |
ShowDetailed | Boolean | Indicates 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. |
ShowDirectory | Boolean | Indicates whether the control also shows directories or not or sets the display of the directories. |
ShowHidden | Boolean | Indicates whether the control also shows hidden files or not or sets the display of hidden files. |
ShowPreview | Boolean | Indicates 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:
The FileView class has these selected methods:
Method | Description |
---|---|
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
The FileView class has the following events, among others:
Event | Description |
---|---|
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
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
Project