home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch09 / gridedit / gridedit.frm (.txt) next >
Encoding:
Visual Basic Form  |  1996-04-24  |  3.5 KB  |  117 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form GridEditForm 
  4.    Caption         =   "Grid Edit"
  5.    ClientHeight    =   4590
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7275
  9.    BeginProperty Font 
  10.       Name            =   "Verdana"
  11.       Size            =   9
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   4590
  20.    ScaleWidth      =   7275
  21.    StartUpPosition =   3  'Windows Default
  22.    Begin VB.TextBox Text1 
  23.       Appearance      =   0  'Flat
  24.       BackColor       =   &H00FF0000&
  25.       ForeColor       =   &H00FFFFFF&
  26.       Height          =   270
  27.       Left            =   60
  28.       TabIndex        =   1
  29.       Top             =   45
  30.       Visible         =   0   'False
  31.       Width           =   1590
  32.    End
  33.    Begin MSFlexGridLib.MSFlexGrid Grid1 
  34.       Height          =   5415
  35.       Left            =   105
  36.       TabIndex        =   0
  37.       Top             =   90
  38.       Width           =   8385
  39.       _ExtentX        =   14790
  40.       _ExtentY        =   9551
  41.       _Version        =   393216
  42.       Rows            =   20
  43.       Cols            =   10
  44.       AllowUserResizing=   3
  45.    End
  46. Attribute VB_Name = "GridEditForm"
  47. Attribute VB_GlobalNameSpace = False
  48. Attribute VB_Creatable = False
  49. Attribute VB_PredeclaredId = True
  50. Attribute VB_Exposed = False
  51. '  ******************************
  52. '  ******************************
  53. '  ** MASTERING VB6            **
  54. '  ** by Evangelos Petroutos   **
  55. '  ** SYBEX, 1998              **
  56. '  ******************************
  57. '  ******************************
  58. Private Sub Form_Load()
  59.     Grid1.ColWidth(0) = TextWidth("99999")
  60.     For i = 1 To Grid1.Rows - 1
  61.         Grid1.TextMatrix(i, 0) = i
  62.         Grid1.RowHeight(i) = 1.25 * Grid1.RowHeight(i)
  63.     Next
  64.     For i = 1 To Grid1.Cols - 1
  65.         Grid1.TextMatrix(0, i) = Chr(64 + i)
  66.     Next
  67.     Grid1.Row = 1
  68.     Grid1.Col = 1
  69.     SetTextbox
  70. End Sub
  71. Private Sub Grid1_EnterCell()
  72. ' Make sure the user doesn't attempt to edit the fixed cells
  73.     If Grid1.MouseRow = 0 Or Grid1.MouseCol = 0 Then
  74.         Text1.Visible = False
  75.         Exit Sub
  76.     End If
  77. ' clear contents of current cell
  78.     Text1.Text = ""
  79. ' place Textbox over current cell
  80.     Text1.Visible = False
  81.     Text1.Top = Grid1.Top + Grid1.CellTop
  82.     Text1.Left = Grid1.Left + Grid1.CellLeft
  83.     Text1.Width = Grid1.CellWidth
  84.     Text1.Height = Grid1.CellHeight
  85. ' assing cell's contents to Textbox
  86.     Text1.Text = Grid1.Text
  87. ' move focus to Textbox
  88.     Text1.Visible = True
  89.     Text1.SetFocus
  90. End Sub
  91. Private Sub Grid1_LeaveCell()
  92.     Grid1.Text = Text1.Text
  93. End Sub
  94. Private Sub Text1_KeyPress(KeyAscii As Integer)
  95.     If KeyAscii = 13 Then
  96.         If Grid1.Row = Grid1.Rows - 1 Then
  97.             If Grid1.Col = Grid1.Cols - 1 Then
  98.                 Exit Sub
  99.             Else
  100.                 Grid1.Col = Grid1.Col + 1
  101.             End If
  102.             Grid1.Row = 1
  103.         Else
  104.             Grid1.Row = Grid1.Row + 1
  105.         End If
  106.     End If
  107. End Sub
  108. Sub SetTextbox()
  109.     Text1.Visible = False
  110.     Text1.Top = Grid1.Top + Grid1.CellTop
  111.     Text1.Left = Grid1.Left + Grid1.CellLeft
  112.     Text1.Height = Grid1.CellHeight
  113.     Text1.Width = Grid1.CellWidth
  114.     Text1.Text = Grid1.Text
  115.     Text1.Visible = True
  116. End Sub
  117.