Tipp 0263 MSHFlexGrid - Direkteingabe über TextBox
Autor/Einsender:
Datum:
  Manuel Schneider
17.08.2002
Entwicklungsumgebung:   VB 6
Dieser Tipp zeigt, wie es mit Hilfe einer TextBox möglich ist, in einem MSHFlexGrid-Steuerelement Daten direkt einzugeben.
 
Option Explicit

Private Sub Form_Load()
  With txtEdit
    .Font = MSHFlexGrid1.Font
    .FontSize = MSHFlexGrid1.Font.Size
    .ForeColor = vbBlue
    .ZOrder (0)
    .Visible = False
  End With
End Sub

Private Sub MSHFlexGrid1_KeyPress(KeyAscii As Integer)
  EditGridText MSHFlexGrid1, txtEdit, KeyAscii
End Sub

Private Sub MSHFlexGrid1_DblClick()
  EditGridText MSHFlexGrid1, txtEdit, vbKeyReturn
End Sub

Private Sub EditGridText(fGrid As MSHFlexGrid, _
        cEdit As TextBox, KeyAscii As Integer)

  Select Case KeyAscii
    Case 0 To 32
      cEdit.Text = fGrid.Text
      cEdit.SelStart = Len(cEdit.Text)

    Case Else
      cEdit.Text = Chr$(KeyAscii)
      cEdit.SelStart = 1
  End Select

  cEdit.Move fGrid.Left + fGrid.CellLeft, _
             fGrid.Top + fGrid.CellTop, _
             fGrid.CellWidth - 8, _
             fGrid.CellHeight - 8
  cEdit.Visible = True
  cEdit.SetFocus
End Sub

Private Sub txtEdit_KeyPress(KeyAscii As Integer)
  If KeyAscii = vbKeyReturn Then KeyAscii = 0
End Sub

Private Sub txtEdit_KeyDown(KeyCode As Integer, Shift As Integer)
  EditTextKeyCode MSHFlexGrid1, txtEdit, KeyCode, Shift
End Sub

Private Sub EditTextKeyCode(fGrid As MSHFlexGrid, _
      cEdit As TextBox, KeyCode As Integer, _
      Shift As Integer)

  Select Case KeyCode
    Case vbKeyEscape
      cEdit.Visible = False
      fGrid.SetFocus

    Case vbKeyReturn
      fGrid.SetFocus
      DoEvents
      With fGrid
        If .Row < .Rows - 1 Then
          .Row = .Row + 1
        End If
      End With
      
    Case vbKeyUp
      fGrid.SetFocus
      DoEvents
      With fGrid
        If .Row > .FixedRows Then
           .Row = .Row - 1
        End If
      End With

    Case vbKeyDown
      fGrid.SetFocus
      DoEvents
      With fGrid
        If .Row < .Rows - 1 Then
          .Row = .Row + 1
        End If
      End With
  End Select
End Sub

Private Sub MSHFlexGrid1_GotFocus()
  If txtEdit.Visible = True Then
    MSHFlexGrid1.Text = txtEdit.Text
    txtEdit.Visible = False
  End If
End Sub

Private Sub MSHFlexGrid1_LeaveCell()
  If txtEdit.Visible = True Then
    MSHFlexGrid1.Text = txtEdit.Text
    txtEdit.Visible = False
  End If
End Sub
 
Weitere Links zum Thema
Markierte Zellen formatieren
Daten aus Textdatei einlesen und speichern
Hinweis
Um diesen Tipp ausführen zu können, muss das Microsoft Hierarchical FlexGrid Control als Komponente in das Projekt  eingebunden werden.

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (3,4 kB) Downloads bisher: [ 2120 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Donnerstag, 8. September 2011