Differenze tra le versioni di "Utilizzare il tasto Tab della tastiera per spostare il cursore del mouse fra le celle di una TableView"

Da Gambas-it.org - Wikipedia.
 
(11 versioni intermedie di uno stesso utente non sono mostrate)
Riga 1: Riga 1:
Mostriamo innanzitutto due esempi che consentono di muoversi fra le celle di una ''TableView'' anche utilizzando il tasto ''Tab''  oltre al tasto "invio" e ai tasti "freccia". Viene mostrato, altresì, un terzo esempio in cui si consentirà l'uso del solo tasto ''Tab'' per ottenere il salto di cella.
+
Mostriamo alcuni esempi che consentono di muoversi fra le celle di una ''TableView'' anche utilizzando il tasto ''Tab''  oltre al tasto "invio" e ai tasti "freccia".
  
 
E' necessario attivare i Componenti ''gb.desktop'' e ''gb.desktop.x11'' .
 
E' necessario attivare i Componenti ''gb.desktop'' e ''gb.desktop.x11'' .
Riga 65: Riga 65:
 
'''2° esempio'''  <SUP>[ [[#Note|Nota 2]] ]</sup>
 
'''2° esempio'''  <SUP>[ [[#Note|Nota 2]] ]</sup>
  
Questo secondo esempio è una leggera variante del codice precedente, e suppone che oltre alla ''TableView'' sia presente sul ''Form'' almeno un altro oggetto (ad esmpio un ''BUutton'').
+
Questo secondo esempio è una variante del codice precedente, e suppone che oltre alla ''TableView'' sia presente sul ''Form'' almeno un altro oggetto (in questo esempio avremo due ''Button'').
 
  '''Public''' Sub Form_Open()
 
  '''Public''' Sub Form_Open()
 
    
 
    
   TableView1.Width = 550
+
   TableView1.Width = 400
   TableView1.Columns.Count = 5
+
   TableView1.Columns.Count = 4
 
   TableView1.Rows.Count = 5
 
   TableView1.Rows.Count = 5
 
   TableView1.Columns[0].Width = 100
 
   TableView1.Columns[0].Width = 100
Riga 75: Riga 75:
 
   TableView1.Columns[2].Width = 100
 
   TableView1.Columns[2].Width = 100
 
   TableView1.Columns[3].Width = 100
 
   TableView1.Columns[3].Width = 100
   
+
     
 
  '''End'''
 
  '''End'''
 
   
 
   
 
   
 
   
 
  '''Public''' Sub TableView1_Click()   
 
  '''Public''' Sub TableView1_Click()   
 +
 
 +
<FONT Color=gray>' ''Impedisce che ai due "Button" possa essere attribuito il Focus con tasto Tab:''</font>
 +
  Button1.NoTabFocus = True
 +
  Button2.NoTabFocus = True
 +
<FONT Color=gray>' ''Però, qualora non vi siano oggetti sul ''Form'', si farà riferimento al solo ''Form'' così:''
 +
' '''Me.NoTabFocus = True'''</font>
 
    
 
    
 
   EditaTableView()
 
   EditaTableView()
Riga 105: Riga 111:
 
   
 
   
 
  '''Private''' Procedure EditaTableView()
 
  '''Private''' Procedure EditaTableView()
 +
 
 +
<FONT Color=gray>' ''Se si intende, dopo aver raggiunto l'ultima cella della "TableView", passare - premendo il tasto "Tab" - il Focus ai due "Button" (decommentare queste righe):''
 +
' '''If (TableView1.Row = TableView1.Rows.Max) And (TableView1.Column = TableView1.Columns.Max) Then'''
 +
'  '''Button1.NoTabFocus = False'''
 +
'  '''Button2.NoTabFocus = False'''
 +
' '''Endif'''</font>
 
    
 
    
 
   TableView1.Edit
 
   TableView1.Edit
 
 
'''End'''
 
 
 
'''Public''' Sub Button1_GotFocus()
 
 
 
  TableView1.SetFocus
 
 
    
 
    
 
  '''End'''
 
  '''End'''
  
  
----
 
  
 +
'''3° esempio'''  <SUP>[ [[#Note|Nota 3]] ]</sup>
  
'''3° esempio'''   <SUP>[ [[#Note|Nota 3]] ]</sup>
+
Questo terzo esempio contempla anche la presenza in talune celle di un tipo di oggetto. Durante lo spostamento, premendo il tasto ''Tab'', da una cella all'altra della ''TableView'', saranno saltate le celle contenenti i predetti oggetti. Dunque il cursore del mouse non capiterà all'interno delle celle occupate dagli oggetti, passando così direttamente alla cella successiva.
  
In questo terzo esempio, invece, si impedisce che anche i tasti "invio" e "freccia" possano sollevare l'evento prescelto per il solo tasto ''Tab''.
+
La particolarità più importante di questo terzo codice è che premendo i tasti ''Shift''+''Tab'' (''BackTab'') il cursore tornerà dietro sino alla prima cella in alto a sinistra della ''TableView'' con le medesime modalità prima viste per le celle occupate dagli oggetti.
 +
Private $bNoEvent As Boolean
 +
Private $colCheck As Integer = 3
 
   
 
   
 
  '''Public''' Sub _new()
 
  '''Public''' Sub _new()
 
    
 
    
   Dim hObs As Observer     <FONT Color=gray>' ''Per anticipare l'evento prima che venga lanciato.''</font>
+
  Dim Ny As Integer
 
+
   Dim hObs As Observer
  hObs = New Observer(Me) As "TableView"
+
 +
  hObs = New Observer(Me) As "TableView"
 +
 
 +
  Me.Center
 +
  TableView1.Header = TableView1.Horizontal
 +
  TableView1.Columns.Count = 6     
 +
  TableView1.Columns[0].Title = "Quantità"
 +
  TableView1.Columns[1].Title = "Oggetto"
 +
  TableView1.Columns[2].Title = "Materiale"
 +
  TableView1.Columns[3].Title = "Pulsante"
 +
  TableView1.Columns[4].Title = "Sconto"
 +
  TableView1.Columns[5].Title = "Importo"
 +
   
 +
  TableView1.Columns[1].Width = 150
 +
  TableView1.Columns[2].Width = 150
 +
 
 +
  TableView1.Rows.Count = 8
 +
 
 +
  TableView1[0, 0].text = "Prova"
 +
  TableView1[1, 0].text = "Hello"
 +
  TableView1[2, 0].text = "Mela"
 +
  TableView1[3, 0].text = "Pesca"
 +
 
 +
  For Ny = 0 To 7
 +
    TableView1[Ny, $colCheck].picture = Picture["off.png"]
 +
  Next
 +
 
 +
  Catch
 +
  Message.Error(Error.Text)
 
    
 
    
 
  '''End'''
 
  '''End'''
 
   
 
   
 
   
 
   
  '''Public''' Sub Form_Open()
+
  '''Public''' Sub TableView1_Click()
 
+
 
  TableView1.Width = 550                          <FONT Color=gray>' ''dichiara la larghezza dell'intera TableView''</font>
+
  If TableView1.Column = 2 Then
  TableView1.Columns.Count = 5                    <FONT Color=gray>' ''dichiara il numero di colonne''</font>
+
    TableView1.Edit(["Giacca", "Pantalone", "Maglia", "Camicia"], False)
  TableView1.Rows.Count = 20                      <FONT Color=gray>' ''dichiara il numero di righe''</font>
+
  Else If TableView1.Column = $colCheck Then
  TableView1.Columns[0].Width = 100              <FONT Color=gray>' ''dichiara la larghezza della colonna ID''</font>
+
    If $bNoEvent = False Then
  TableView1.Columns[1].Width = 100              <FONT Color=gray>' ''dichiara la larghezza della colonna Luogo''</font>
+
      If TableView1.Current.Picture = Picture["on.png"] Then
  TableView1.Columns[2].Width = 100              <FONT Color=gray>' ''dichiara la larghezza della colonna GRP''</font>
+
        TableView1.Current.Picture = Picture["off.png"]
  TableView1.Columns[3].Width = 100              <FONT Color=gray>' ''dichiara la larghezza della colonna stato''</font>
+
      Else
  TableView1.Columns[4].Alignment = Align.Center  <FONT Color=gray>' ''centra i pulsanti''</font>
+
        TableView1.current.Picture = Picture["on.png"]
  TableView1.Rows.Height = 30                    <FONT Color=gray>' ''dichiara l'altezza della riga''</font>
+
      Endif
  TableView1.name = "PROVA"
+
    Else
  TableView1.Header = 3                          <FONT Color=gray>' ''ATTIVA L'INTESTAZIONE DELLE COLONNE''</font>
+
      $bNoEvent = False
  TableView1.Font.Size = 11
+
    Endif
  TableView1.Columns[0].Alignment = 3            <FONT Color=gray>' ''Allineamento centrato''</font>
+
  Else
  TableView1.Columns[1].Alignment = 3            <FONT Color=gray>' ''Allineamento centrato''</font>
+
    TableView1.Edit
  TableView1.Columns[2].Alignment = 3            <FONT Color=gray>' ''Allineamento centrato''</font>
+
  End If
  TableView1.Columns[3].Alignment = 3            <FONT Color=gray>' ''Allineamento centrato''</font>
+
 
     
 
 
  '''End'''
 
  '''End'''
 
   
 
   
 
   
 
   
  '''Public''' Sub TableView1_Click()  <FONT Color=gray>' ''Evento non osservato''</font>
+
  '''Public''' Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
 
+
    
  TableView1.Edit
+
  TableView1[row, column].text = value
     
+
 
 
  '''End'''
 
  '''End'''
 
   
 
   
 
   
 
   
  '''Public''' Sub TableView1_Save(Row As Integer, Column As Integer, Value As String<FONT Color=gray>' ''Serve per salvare il testo scritto all'interno delle celle.''</font>
+
  '''Public''' Sub TableView_KeyPress()
 
+
    
  TableView1[row, column].text = value
+
  Dim i As Integer
 
 
'''End'''
 
 
    
 
    
 
+
   Select Case Key.Code
'''Public''' Sub TableView_KeyPress()  <FONT Color=gray>' ''Evento osservato''</font>
+
     Case Key.Right, Key.Left, Key.Return, Key.Enter
 
+
       If TableView1.Column = $colCheck - 1 Or $colCheck + 1 Then
<FONT Color=gray>' ''Per impedire a questi eventi di scatenare il click quando passano alla riga successiva.</font> 
 
   Select Case Key.Code  
 
     Case Key.Right, Key.Return, Key.Enter
 
       If TableView1.Column = 3 Then    
 
 
         $bNoEvent = True
 
         $bNoEvent = True
       Endif  
+
       Endif
<FONT Color=gray>' ''Serve per spostarsi con tasto Tab:''</font>
+
   
     Case Key.Tab    
+
     Case Key.Tab
       If Application.ActiveControl = TextBox1 Then       
+
       Stop Event
        If TableView1.Row = -1 Then         
+
      Desktop.SendKeys("\n")
          Desktop.SendKeys("\t")
+
   
           Return
+
    Case Key.BackTab
        Endif    
+
      Stop Event
        If TableView1.Row = TableView1.Rows.Count - 1 And TableView1.Column = TableView1.Columns.Count - 2 Then           
+
           If TableView1.row = 0 And TableView1.Column = 0 Then
          Desktop.SendKeys("\t")
+
              Return
        Else
+
          Endif
          Stop Event
+
      i = TableView1.Column
          Desktop.SendKeys("\n")
+
      If TableView1.Column = 0 Then
        Endif
+
        i = TableView1.Columns.Max + 1
      Endif   
+
        TableView1.Row = TableView1.Row - 1
   End Select
+
      Endif
     
+
      If TableView1.Column = $colCheck + 1 Then
 +
         $bNoEvent = True
 +
        TableView1.MoveTo(TableView1.Row, i - 2)
 +
      Else
 +
        TableView1.MoveTo(TableView1.Row, i - 1)
 +
      Endif
 +
      TableView1.Edit
 +
   End Select
 +
 
 
  '''End'''
 
  '''End'''
  
Riga 204: Riga 240:
 
[2] Il codice è a cura del membro [http://www.gambas-it.org/smf/index.php?action=profile;u=402 vuott] del forum gambas-org.it
 
[2] Il codice è a cura del membro [http://www.gambas-it.org/smf/index.php?action=profile;u=402 vuott] del forum gambas-org.it
  
[3] Il codice è a cura del membro [http://www.gambas-it.org/smf/index.php?action=profile;u=1249 Gianluigi] del forum gambas-org.it
+
[3] Il codice è a cura del membro [http://www.gambas-it.org/smf/index.php?action=profile;u=151 Golia] del forum gambas-org.it

Versione attuale delle 11:11, 14 ott 2016

Mostriamo alcuni esempi che consentono di muoversi fra le celle di una TableView anche utilizzando il tasto Tab oltre al tasto "invio" e ai tasti "freccia".

E' necessario attivare i Componenti gb.desktop e gb.desktop.x11 .


1° esempio [ Nota 1 ]

Public Sub _new()
 
 Dim hObs As Observer     ' Per anticipare l'evento prima che venga lanciato.
  
  hObs = New Observer(Me) As "TableView"
 
End


Public Sub Form_Open()
  
  TableView1.Width = 550                          ' dichiara la larghezza dell'intera TableView
  TableView1.Columns.Count = 5                    ' dichiara il numero di colonne
  TableView1.Rows.Count = 20                      ' dichiara il numero di righe
  TableView1.Columns[0].Width = 100               ' dichiara la larghezza della colonna ID
  TableView1.Columns[1].Width = 100               ' dichiara la larghezza della colonna Luogo
  TableView1.Columns[2].Width = 100               ' dichiara la larghezza della colonna GRP
  TableView1.Columns[3].Width = 100               ' dichiara la larghezza della colonna stato
  TableView1.Columns[4].Alignment = Align.Center  ' centra i pulsanti
  TableView1.Rows.Height = 30                     ' dichiara l'altezza della riga
  TableView1.name = "PROVA"
  TableView1.Header = 3                           ' ATTIVA L'INTESTAZIONE DELLE COLONNE
  TableView1.Font.Size = 11
  TableView1.Columns[0].Alignment = 3             ' Allineamento centrato
  TableView1.Columns[1].Alignment = 3             ' Allineamento centrato
  TableView1.Columns[2].Alignment = 3             ' Allineamento centrato
  TableView1.Columns[3].Alignment = 3             ' Allineamento centrato
     
End


Public Sub TableView1_Click()   ' Evento non osservato
  
  TableView1.Edit
     
End


Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)   ' Serve per salvare il testo scritto all'interno delle celle.
  
  TableView1[row, column].text = value
  
End
 
  
Public Sub TableView_KeyPress()   ' Evento osservato
  
' Serve per spostarsi con tasto Tab:
    If Key.Code = Key.Tab
      Stop Event            ' Lo "Stop Event" consente alla successiva linea Desktop.SendKeys("\n") di funzionare.
      Desktop.SendKeys("\n")
    Endif
     
End


2° esempio [ Nota 2 ]

Questo secondo esempio è una variante del codice precedente, e suppone che oltre alla TableView sia presente sul Form almeno un altro oggetto (in questo esempio avremo due Button).

Public Sub Form_Open()
 
 TableView1.Width = 400
 TableView1.Columns.Count = 4
 TableView1.Rows.Count = 5
 TableView1.Columns[0].Width = 100
 TableView1.Columns[1].Width = 100
 TableView1.Columns[2].Width = 100
 TableView1.Columns[3].Width = 100
     
End


Public Sub TableView1_Click()   
 
' Impedisce che ai due "Button" possa essere attribuito il Focus con tasto Tab:
 Button1.NoTabFocus = True
 Button2.NoTabFocus = True
' Però, qualora non vi siano oggetti sul Form, si farà riferimento al solo Form così:
' Me.NoTabFocus = True
 
 EditaTableView()
 
End


Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
  
 TableView1[row, column].text = value
  
End
 
 
Public Sub TableView1_KeyRelease()  
 
' Serve per spostarsi con tasto Tab:
 If Key.Code = Key.Tab
   Desktop.SendKeys("\n")
   EditaTableView()
 Endif
 
End


Private Procedure EditaTableView()
 
' Se si intende, dopo aver raggiunto l'ultima cella della "TableView", passare - premendo il tasto "Tab" - il Focus ai due "Button" (decommentare queste righe):
' If (TableView1.Row = TableView1.Rows.Max) And (TableView1.Column = TableView1.Columns.Max) Then
'   Button1.NoTabFocus = False
'   Button2.NoTabFocus = False
' Endif
 
 TableView1.Edit
 
End


3° esempio [ Nota 3 ]

Questo terzo esempio contempla anche la presenza in talune celle di un tipo di oggetto. Durante lo spostamento, premendo il tasto Tab, da una cella all'altra della TableView, saranno saltate le celle contenenti i predetti oggetti. Dunque il cursore del mouse non capiterà all'interno delle celle occupate dagli oggetti, passando così direttamente alla cella successiva.

La particolarità più importante di questo terzo codice è che premendo i tasti Shift+Tab (BackTab) il cursore tornerà dietro sino alla prima cella in alto a sinistra della TableView con le medesime modalità prima viste per le celle occupate dagli oggetti.

Private $bNoEvent As Boolean
Private $colCheck As Integer = 3

Public Sub _new()
 
 Dim Ny As Integer
 Dim hObs As Observer

 hObs = New Observer(Me) As "TableView"  
 
 Me.Center
 TableView1.Header = TableView1.Horizontal
 TableView1.Columns.Count = 6       
 TableView1.Columns[0].Title = "Quantità"
 TableView1.Columns[1].Title = "Oggetto"
 TableView1.Columns[2].Title = "Materiale"
 TableView1.Columns[3].Title = "Pulsante"
 TableView1.Columns[4].Title = "Sconto"
 TableView1.Columns[5].Title = "Importo"
    
 TableView1.Columns[1].Width = 150 
 TableView1.Columns[2].Width = 150
 
 TableView1.Rows.Count = 8
 
 TableView1[0, 0].text = "Prova"
 TableView1[1, 0].text = "Hello"
 TableView1[2, 0].text = "Mela"
 TableView1[3, 0].text = "Pesca"
 
 For Ny = 0 To 7
   TableView1[Ny, $colCheck].picture = Picture["off.png"]
 Next
 
 Catch
 Message.Error(Error.Text)
 
End


Public Sub TableView1_Click()
 
 If TableView1.Column = 2 Then
   TableView1.Edit(["Giacca", "Pantalone", "Maglia", "Camicia"], False)
 Else If TableView1.Column = $colCheck Then
   If $bNoEvent = False Then
     If TableView1.Current.Picture = Picture["on.png"] Then 
       TableView1.Current.Picture = Picture["off.png"]
     Else
       TableView1.current.Picture = Picture["on.png"]
     Endif
   Else
     $bNoEvent = False
   Endif
 Else
   TableView1.Edit
 End If
 
End


Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
 
 TableView1[row, column].text = value
 
End


Public Sub TableView_KeyPress()
 
 Dim i As Integer
 
 Select Case Key.Code
   Case Key.Right, Key.Left, Key.Return, Key.Enter
     If TableView1.Column = $colCheck - 1 Or $colCheck + 1 Then
       $bNoEvent = True
     Endif
   
   Case Key.Tab
     Stop Event 
     Desktop.SendKeys("\n")
   
   Case Key.BackTab
      Stop Event 
         If TableView1.row = 0 And TableView1.Column = 0 Then 
             Return  
         Endif
      i = TableView1.Column
      If TableView1.Column = 0 Then 
        i = TableView1.Columns.Max + 1
        TableView1.Row = TableView1.Row - 1
      Endif
      If TableView1.Column = $colCheck + 1 Then
        $bNoEvent = True
        TableView1.MoveTo(TableView1.Row, i - 2)
      Else
        TableView1.MoveTo(TableView1.Row, i - 1)
      Endif
      TableView1.Edit
 End Select
 
End



Note

[1] Il codice è a cura del membro Gianluigi del forum gambas-org.it

[2] Il codice è a cura del membro vuott del forum gambas-org.it

[3] Il codice è a cura del membro Golia del forum gambas-org.it