User Tools

Site Tools


k20:k20.9:start

20.9 Select

The Select (gb.qt4) class provides three constants (→ Table 20.9.1.1) for specifying the mode properties of many components. These components include:

ColumnView, DateBox, DateChooser, FileView, GridView, IconView, LCDNumber, ListBox, ListView, Stat, TableView, TreeView and _TreeView.

20.9.1 Constants

SelectConstantDescription
None0No selection of elements is possible for the selected component.
Single1The component allows single selection (default).
Multiple2Multiple selection is possible for the selected component by holding down the CTRL key or SHIFT key (block).

Table 20.9.1.1: Constants of the Select Class

20.9.2 Project

In the project presented, two constants (Select.Single and Select.Multiple) are used to specify the file selection options in the FileView component:

B1

Figure 20.9.2.1: Mode: Select.Single

B2

Figure 20.9.2.2: Mode: Select.Multiple

Notes:

  • When a file is single-selected, the file path is specified.
  • For multiple selection, only the file names are displayed in a list in a TextBox. The separator is the pipe character.
  • You can select multiple files (one at a time) in 'Multiple' select mode by holding down the CTRL key while selecting. A block selection of several files in a row can be achieved by holding down the SHIFT key after the 1st selection and selecting the last file in the block. In both cases, the file list of the selected files will be readable in the property FileView1.Selection (DataType Array).
  • When switching from multiple selection to single selection, the last file from the multiple selection list will be displayed with full path.
  • When switching from the single selection to the multiple selection, no file is displayed.
  • The current select mode for the FileView component is displayed in the StatusBar (→ Chapter 18.14 StatusBar).

The source code is manageable and is therefore given in full:

' Gambas class file
 
Private myStatusbar As Statusbar
 
Public Sub Form_Open()
 
  FMain.Center()
  FMain.Resizable = False
 
  DirView1.Root = User.Home
  txbDirectory.Text = DirView1.Current
  txbFile.Clear()
 
  Timer1.Delay = 1000
  Timer1.Start()
 
  myStatusbar = New Statusbar(Me)
  myStatusbar.Add(0.3, Format$(Now, "dddd, dd/mm/yyyy hh:nn:ss")) '-- 0.3 → 30% of the StatusBar width
  myStatusBar.SetBackground(0, &HEFFFDF)
  myStatusBar.SetForeground(0, &H000000)
  myStatusbar.SetToolTip(0, "Datum&Zeit")
  myStatusbar.SetAlignment(0, Align.Center)
 
  myStatusbar.Add(0.3, "Select-Mode:   Select.Single") '-- Start setting
  myStatusBar.SetBackground(1, &HFFFFDF)
  myStatusbar.SetAlignment(1, Align.Center)
 
' -- The field length is automatically set at the last field → enter 0
  myStatusbar.Add(0, "Program version = " & Application.Version)
  myStatusBar.SetBackground(2, &HEFFFDF)
  myStatusbar.SetAlignment(2, Align.Center)
 
  btnFileSelectMode.Picture = Picture["Symbols/multiple.png"]
  btnFileSelectMode.Value = False
 
End
 
Public Sub Timer1_Timer()
 
'-- Timer1_Timer() : Show current time in panel 0 of the StatusBar
    myStatusbar.SetText(0, Format$(Now, "dddd, dd/mm/yyyy hh:nn:ss"))
 
End
 
Public Sub DirView1_Select()
  FileView1.Dir = DirView1.Current
  txbDirectory.Text = DirView1.Current
  txbFile.Clear()
  FileView1.Mode = Select.Multiple
  lblFile.Text = "File list: "
  txbFile.Clear
End
 
Public Sub FileView1_Click()
  Dim sElement As String
 
  txbFile.Clear
  txbFile.Text = "| "
  If FileView1.Mode = Select.Single Then
     txbFile.Text = DirView1.Current &/ FileView1.Current
  Else
     For Each sElement In FileView1.Selection '-- FileView1.Selection = Array with the selected files
         txbFile.Text &= sElement & " | "
     Next
  Endif
 
End
 
Public Sub btnFileSelectMode_Click()
 
  If btnFileSelectMode.Value = True Then '-- If True, then Select.Multiple is active
     btnFileSelectMode.Picture = Picture["Symbols/single.png"]
     btnFileSelectMode.Tooltip = "Switch to select mode 'Single'"
     FileView1.Mode = Select.Multiple
     lblFile.Text = "File list: "
     txbFile.Clear()
     myStatusbar.SetText(1, "Select-Mode:   Select.Multiple")
  Else
     btnFileSelectMode.Picture = Picture["Symbols/multiple.png"]
     btnFileSelectMode.Tooltip = "Switch to Select mode 'Multiple'"
     FileView1.Mode = Select.Single
     lblFile.Text = "File path: "
     If FileView1.Selection.Count > 0 Then
        txbFile.Text = DirView1.Current &/ FileView1.Selection[0]
     Endif
     myStatusbar.SetText(1, "Select-Mode:   Select.Single")
  Endif
 
End
 
Public Sub btnClose_Click()
  FMain.Close()
End ' btnClose_Click()
 
Public Sub Form_Close()
  myStatusBar.Delete()
End

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k20/k20.9/start.txt · Last modified: 22.10.2023 by emma

Page Tools