' Gambas class file Inherits GridView Export Event Save(Row As Integer, Column As Integer, Value As String) Event Insert Event Click Property Read Editor As Control Private $hTextBox As TextBox Private $hComboBox As ComboBox Private $hEditor As Object Private $bTextBox As Boolean Private $iCol As Integer Private $iRow As Integer Private $hWatcher As Watcher Public Sub _new() Dim hObs As Observer hObs = New Observer(Me) As "GridView" $hWatcher = New Watcher(Me) As "GridView" $hComboBox = New ComboBox(Me.Window) As "Editor" $hComboBox.Ignore = True $hComboBox.Hide $hTextBox = New TextBox(Me.Window) As "Editor" $hTextBox.Ignore = True $hTextBox.Border = False $hTextBox.Hide End Private Sub SaveEditor() Dim sText As String Dim sCurrent As String Try sCurrent = Me[$iRow, $iCol].Text If Error Then Return Try sText = $hEditor.Text If sText = sCurrent Then Return Raise Save($iRow, $iCol, sText) Me[$iRow, $iCol].Refresh End Public Sub Save() HideEditor End Public Sub Cancel() HideEditor(True) End Private Sub HideEditor(Optional bNoSave As Boolean) If $hEditor Then If Not bNoSave Then SaveEditor $hEditor.Hide $hEditor = Null Endif End Private Sub MoveEditor() Dim X, Y As Integer If Not $hEditor Then Return X = Me.ScreenX - Me.Window.ScreenX - Me.Window.ClientX Y = Me.ScreenY - Me.Window.ScreenY - Me.Window.ClientY 'DEBUG $iRow;; $iCol With Me[$iRow, $iCol] X += .X Y += .Y $hEditor.Move(X, Y, .Width, .Height) 'DEBUG ' Debug .X;; .Y;; .W;; .H;; "/";; Me.ClientW;; Me.ClientH;; "/";; Me.W;; Me.H ' ' If .X < 0 Or If .Y < 0 Or If (.X + .W) > Me.W Or If (.Y + .H) > Me.H Then ' ' HideEditor ' ' Else $hEditor.Font = Me.Font $hEditor.Show 'DEBUG End With End Public Sub GridView_MouseDown() HideEditor End Public Sub GridView_RowResize(Row As Integer) HideEditor End Public Sub GridView_ColumnResize(Column As Integer) HideEditor End Public Sub GridView_Scroll() HideEditor End Public Sub GridView_Resize() HideEditor End Public Sub GridView_Hide() HideEditor End Public Sub GridView_Change() HideEditor End Public Sub Edit(Optional List As String[], Optional ReadOnly As Boolean) 'DEBUG HideEditor $iCol = Me.Column $iRow = Me.Row If $iCol < 0 Or $iRow < 0 Then Return If List Then $hComboBox.List = List $hComboBox.ReadOnly = ReadOnly $hEditor = $hComboBox $bTextBox = Not ReadOnly Else $hEditor = $hTextBox $bTextBox = True Endif $hEditor.Text = Me[$iRow, $iCol].Text Try $hEditor.SelectAll MoveEditor Try $hEditor.SetFocus End Public Sub EditWith(Editor As Control) HideEditor $iCol = Me.Column $iRow = Me.Row If $iCol < 0 Or $iRow < 0 Then Return $hEditor = Editor $bTextBox = False Try $hEditor.Text = Me[$iRow, $iCol].Text If Error Then $hEditor = Null Error.Raise("The TableView editor must have a Text public property") Endif Try $hEditor.SelectAll MoveEditor Try $hEditor.SetFocus End Public Sub Editor_Activate() SaveEditor End Public Sub Editor_Click() SaveEditor End Public Sub Editor_KeyPress() Select Case Key.Code Case Key.Escape $hEditor.Text = Me[$iRow, $iCol].Text Stop Event Case Key.Up While Me.Row > 0 Dec Me.Row Raise Click If $hEditor Then Stop Event Break Endif Wend Case Key.Down While Me.Row < (Me.Rows.Count - 1) Inc Me.Row Raise Click If $hEditor Then Stop Event Break Endif Wend Case Key.Left If $bTextBox Then If $hEditor.Pos = 0 Then Do If Me.Column > 0 Then Dec Me.Column Raise Click Else If Me.Row > 0 Then Me.MoveTo(Me.Row - 1, Me.Columns.Count - 1) Raise Click Else Break Endif If $hEditor Then $hEditor.Pos = $hEditor.Length Stop Event Break Endif Loop Endif Endif Case Key.Right If $bTextBox Then If $hEditor.Pos = $hEditor.Length Then Do If Me.Column < (Me.Columns.Count - 1) Then Inc Me.Column Raise Click Else If Me.Row < (Me.Rows.Count - 1) Then Me.MoveTo(Me.Row + 1, 0) Raise Click Else Break Endif If $hEditor Then $hEditor.Pos = 0 Stop Event Break Endif Loop Endif Endif Case Key.Enter, Key.Return If $bTextBox Then Do If Me.Column < (Me.Columns.Count - 1) Then Inc Me.Column Raise Click Else If Me.Row < (Me.Rows.Count - 1) Then Me.MoveTo(Me.Row + 1, 0) Raise Click Else Raise Insert Stop Event Break Endif If $hEditor Then $hEditor.Pos = 0 Stop Event Break Endif Loop Endif End Select End Private Function Editor_Read() As Control Return $hEditor End