home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / msflex3a / gridlite.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1999-09-24  |  14.0 KB  |  405 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form BackGrnd 
  4.    AutoRedraw      =   -1  'True
  5.    BorderStyle     =   1  'Fixed Single
  6.    Caption         =   "Test Grid Lite"
  7.    ClientHeight    =   3360
  8.    ClientLeft      =   45
  9.    ClientTop       =   360
  10.    ClientWidth     =   4695
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    Moveable        =   0   'False
  15.    ScaleHeight     =   3360
  16.    ScaleWidth      =   4695
  17.    StartUpPosition =   2  'CenterScreen
  18.    Begin VB.CheckBox AutoReturn 
  19.       Caption         =   "Auto Return to Col. 1"
  20.       Height          =   255
  21.       Left            =   2640
  22.       TabIndex        =   3
  23.       TabStop         =   0   'False
  24.       Top             =   120
  25.       Width           =   1815
  26.    End
  27.    Begin VB.CommandButton Stop 
  28.       Caption         =   "STOP"
  29.       Height          =   375
  30.       Left            =   1920
  31.       TabIndex        =   1
  32.       Top             =   2880
  33.       Width           =   975
  34.    End
  35.    Begin MSFlexGridLib.MSFlexGrid FG1 
  36.       Height          =   2415
  37.       Left            =   240
  38.       TabIndex        =   0
  39.       Top             =   360
  40.       Width           =   4215
  41.       _ExtentX        =   7435
  42.       _ExtentY        =   4260
  43.       _Version        =   393216
  44.       Rows            =   30
  45.       Cols            =   10
  46.       AllowBigSelection=   0   'False
  47.       ScrollTrack     =   -1  'True
  48.       FillStyle       =   1
  49.    End
  50.    Begin VB.Label CellIndicator 
  51.       Appearance      =   0  'Flat
  52.       AutoSize        =   -1  'True
  53.       BackColor       =   &H80000005&
  54.       BorderStyle     =   1  'Fixed Single
  55.       ForeColor       =   &H80000008&
  56.       Height          =   255
  57.       Left            =   240
  58.       TabIndex        =   2
  59.       Top             =   120
  60.       UseMnemonic     =   0   'False
  61.       Width           =   105
  62.    End
  63.    Begin VB.Menu MnuFGridRows 
  64.       Caption         =   "Rows"
  65.       Visible         =   0   'False
  66.       Begin VB.Menu MnuFGridAddRow 
  67.          Caption         =   "Add a Row"
  68.       End
  69.       Begin VB.Menu MnuFGridInsRow 
  70.          Caption         =   "Insert a Row"
  71.       End
  72.       Begin VB.Menu MnuFGridSep1 
  73.          Caption         =   "-"
  74.       End
  75.       Begin VB.Menu MnuFGridDelRow 
  76.          Caption         =   "Delete a Row"
  77.       End
  78.       Begin VB.Menu MnuFGridExtrRow 
  79.          Caption         =   "Extract a Row"
  80.       End
  81.    End
  82.    Begin VB.Menu MnuFGridCols 
  83.       Caption         =   "Columns"
  84.       Visible         =   0   'False
  85.       Begin VB.Menu MnuFGridAddCol 
  86.          Caption         =   "Add a Col"
  87.       End
  88.       Begin VB.Menu MnuFGridInsCol 
  89.          Caption         =   "Insert a Col"
  90.       End
  91.       Begin VB.Menu MnuFGridSep2 
  92.          Caption         =   "-"
  93.       End
  94.       Begin VB.Menu MnuFGridDelCol 
  95.          Caption         =   "Delete a Col"
  96.       End
  97.       Begin VB.Menu MnuFGridExtrCol 
  98.          Caption         =   "Extract a Col"
  99.       End
  100.    End
  101. Attribute VB_Name = "BackGrnd"
  102. Attribute VB_GlobalNameSpace = False
  103. Attribute VB_Creatable = False
  104. Attribute VB_PredeclaredId = True
  105. Attribute VB_Exposed = False
  106. 'MSFlexgrid Edit Lite: 9-17-99
  107. 'this is an effective and completely natural looking way
  108. 'to edit data in the MSFlexgrid object. I've chosen to keep
  109. 'all columns the same width that is why I've used .TextMatrix
  110. 'in Form_Load() below rather than .FormatString.
  111. 'If you don't care that numbers and chars wind up aligned
  112. 'differently in the columns then remove .ColAlignment(-1)=1
  113. 'in the Form_Load() sub.
  114. 'Move the cell around with the cursor keys or click with
  115. 'the mouse on the destination cell.
  116. 'Starting to type will add to the current value in that cell.
  117. 'If you change your mind while editing, press <ESC> to restore.
  118. '<Del> will delete cell contents. <ESC> lets you change
  119. 'your mind an restore the original figure or the last
  120. 'figure (in curr. cell) before pressing <Del>.
  121. 'You can enter a cell, drag the mouse and then start typing and
  122. 'VOILA you fill in all the hi-lited cells. The same thing can
  123. 'be achieved by pressing the SHIFT & CURSOR keys. (This is also
  124. 'an effective way of erasing a whole block of data.)
  125. '<ENTER> key or Arrow keys advance to the next cell.
  126. 'Navigtion keys are the usual <Home>, <End>, <Pg Up / Dn>
  127. 'along with their Ctrl alternates
  128. 'The Cell indicator - may come in handy in BIG Grids
  129. 'Also, a choice button to automatically return the focus
  130. 'to the first column or just go down 1 row.
  131. 'Similar thing can be accomplished like so:
  132. '( in Incr_Cell() )
  133. '   if Fg1.ColIsVisible(1) then
  134. '       FG1.Col=1
  135. '   end if
  136. 'This is the lite version of the MSFlexgrid file postet on
  137. 'Sept. 12,99. It does everything that version did except-
  138. 'In-Cell-Editing with In-Cell-Cursor - but, unless you do
  139. 'a lot of LONG entries this'll do the trick and is less code.
  140. 'If you can improve the code...COOL, let me know.
  141. '9-23-99
  142. 'I took the label L1 out. Temporary strings are now stored
  143. 'in FG1.Tag (MSFlexgrid does not use it!).
  144. 'In FG1_LeaveCell() I've added a Format$("0.00") for display
  145. 'you can NIX that if you don't want it.
  146. 'Typing into a cell with existing data ADDS to the exist. If you
  147. 'want to erase the exist data press <DEL>, but if you then
  148. 'change your mind you can press <ESC> to restore the text that
  149. 'was there when you re-entered the cell.
  150. 'also added Popupmenus for Adding, Deleting, Inserting and
  151. 'Extracting either Rows or Cols.
  152. 'Just put mouse in Col 0 or Row 0 and click Right Mouse Button.
  153. 'Add - means add Row at bottom or Col at end
  154. 'Delete - means del LAST Row or LAST Col
  155. 'Insert - means INSERT a Row / Col at present cursor pos.
  156. 'Extract - means EXTRACT a Row /Col at present cursor pos.
  157. 'If you try to DELETE / EXTRACT a Row / Col that has data
  158. 'in it you will be prompted if you wish to proceed.
  159. 'The Popupmenus were created the usual way and then had their
  160. 'Titles set to : Visible = False
  161. 'Now posted as as .vbp file
  162. 'Peter Raddatz - lupo@unix.infoserve.net
  163. Private Sub Form_Load()
  164.     Dim y%
  165.     With FG1
  166.         .ColAlignment(-1) = 1       'all Left alligned
  167.     For y% = 1 To .Cols - 1
  168.         .TextMatrix(0, y%) = "Col " + Str(y%)
  169.     Next
  170.     For y% = 1 To FG1.Rows - 1
  171.         .TextMatrix(y%, 0) = "Row " + Str(y%)
  172.     Next
  173.         .Row = 1
  174.         .Col = 1
  175.         .CellBackColor = &HC0FFFF   'lt. yellow
  176.         BackGrnd.CellIndicator = " " + .TextMatrix(.Row, 0) + " : " + .TextMatrix(0, .Col) + " "
  177.         'display current row & col in a boxed label
  178.     End With
  179. End Sub
  180. Private Sub AutoReturn_Click()
  181.     FG1.SetFocus
  182. End Sub
  183. Private Sub FG1_EnterCell()
  184.     BackGrnd.CellIndicator = " " + FG1.TextMatrix(FG1.Row, 0) + " : " + FG1.TextMatrix(0, FG1.Col) + " "
  185.     'update current row & col in boxed label
  186.     FG1.CellBackColor = &HC0FFFF    'lt. yellow
  187.     FG1.Tag = ""                    'clear temp storage
  188. End Sub
  189. Private Sub FG1_LeaveCell()
  190.     FG1 = Format$(FG1, "0.00")      'or whatever format
  191.     FG1.CellBackColor = &H80000005  'white
  192. End Sub
  193. Private Sub FG1_KeyDown(KeyCode As Integer, Shift As Integer)
  194. Select Case KeyCode
  195.     Case 46             '<Del>, clear cell
  196.         FG1.Tag = FG1   'assign to temp storage
  197.         FG1 = ""        'Null
  198. End Select
  199. End Sub
  200. Private Sub FG1_KeyPress(KeyAscii As Integer)
  201.     Select Case KeyAscii
  202.         Case 13         'ENTER key
  203.             KeyCode = 0 'don't beep
  204.             INCR_CELL   'advance new cell
  205.         Case 8          'BkSpc
  206.             If Len(FG1) Then
  207.                 FG1 = Left$(FG1, Len(FG1) - 1)  'shorten text
  208.             End If
  209.         Case 27                     'ESC
  210.             If FG1.Tag > "" Then    'only if not NULL$
  211.                 FG1 = FG1.Tag       'restore orig. text
  212.             End If
  213.         Case Else
  214.             FG1 = FG1 + Chr(KeyAscii)
  215.     End Select
  216. End Sub
  217. Private Sub FG1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  218. Dim Row%, Col%
  219. Row% = FG1.MouseRow
  220. Col% = FG1.MouseCol
  221. If Button = 2 And (Col% = 0 Or Row% = 0) Then
  222.     FG1.Col = IIf(Col% = 0, 1, Col%)    'rows?
  223.     FG1.Row = IIf(Row% = 0, 1, Row%)    'or cols?
  224.     If Col% Then
  225.         PopupMenu MnuFGridCols
  226.     Else
  227.         PopupMenu MnuFGridRows
  228.     End If
  229. End If
  230. End Sub
  231. Private Sub MnuFGridAddCol_Click()
  232. With FG1
  233.     .Cols = .Cols + 1
  234.     .Col = .Cols - 1
  235.     .TextMatrix(0, .Col) = "Col " + Str(.Col)   'add title
  236. End With
  237. IsCellVisible           'make sure!
  238. End Sub
  239. Private Sub MnuFGridAddRow_Click()
  240. With FG1
  241.     .Rows = .Rows + 1
  242.     .Row = .Rows - 1
  243.     .TextMatrix(.Row, 0) = "Row " + Str(.Row)
  244. End With
  245. IsCellVisible
  246. End Sub
  247. Private Sub MnuFGridDelCol_Click()
  248. Dim R%, C%, Col%
  249. If FG1.Cols > 2 Then        'make sure we don't del col 1
  250.     Col% = FG1.Cols - 1     'last col
  251.     For R% = 1 To FG1.Rows - 1  'Check for data in .Col
  252.         If FG1.TextMatrix(R%, Col%) > "" Then   'data?
  253.             C% = 1              'Yes there is!
  254.             Exit For
  255.         End If
  256.     Next R%
  257.     If C% Then                  'send warning
  258.         R% = MsgBox("There is data in Col" + Str$(Col%) + " ! Delete anyway?", vbYesNo, "Delete Column!")
  259.     End If
  260.     If C% = 0 Or R% = 6 Then    'no exist data or YES
  261.         If FG1.Col = FG1.Cols - 1 Then  'last col?
  262.             FG1.Col = FG1.Col - 1       'move active cell
  263.         End If
  264.         FG1.Cols = FG1.Cols - 1         'del lat col
  265.     End If
  266. End If
  267. End Sub
  268. Private Sub MnuFGridDelRow_Click()
  269. Dim R%, C%, Row%
  270. If FG1.Rows > 2 Then        'make sure we don't del row 1
  271.     Row% = FG1.Rows - 1
  272.     For R% = 1 To FG1.Cols - 1
  273.         If FG1.TextMatrix(Row%, R%) > "" Then   'data?
  274.             C% = 1
  275.             Exit For
  276.         End If
  277.     Next R%
  278.     If C% Then
  279.         R% = MsgBox("There is data in Row" + Str$(Row%) + " ! Delete anyway?", vbYesNo, "Delete Row!")
  280.     End If
  281.     If C% = 0 Or R% = 6 Then        'no exist. data or YES
  282.         If FG1.Row = FG1.Rows - 1 Then  'last row?
  283.             FG1.Row = FG1.Row - 1       'move active cell
  284.         End If
  285.         FG1.Rows = FG1.Rows - 1     'del last row
  286.     End If
  287. End If
  288. End Sub
  289. Private Sub MnuFGridInsRow_Click()
  290. Dim R%, Row%, Col%
  291. With FG1
  292.     R% = .Row
  293.     .Rows = .Rows + 1               'add a row
  294.     .TextMatrix(.Rows - 1, 0) = "Row " + Str$(.Rows - 1)    'new row title
  295.     For Row% = .Rows - 1 To R% + 1 Step -1 'move data dn 1 row
  296.         For Col% = 1 To .Cols - 1
  297.             .TextMatrix(Row%, Col%) = .TextMatrix(Row% - 1, Col%)
  298.         Next Col%
  299.     Next Row%
  300.     For Col% = 1 To .Cols - 1       ' clear all cells in this row
  301.         .TextMatrix(R%, Col%) = ""
  302.     Next Col%
  303. End With
  304. End Sub
  305. Private Sub MnuFGridInsCol_Click()
  306. Dim C%, Row%, Col%
  307. With FG1
  308.     C% = .Col
  309.     .Cols = .Cols + 1               'add a col
  310.     .ColAlignment(-1) = 1           'set col alignment
  311.     .TextMatrix(0, .Cols - 1) = "Col " + Str(.Cols - 1) 'new col title
  312.     For Row% = 1 To .Rows - 1       'move exist. data over
  313.         For Col% = .Cols - 1 To C% + 1 Step -1
  314.             .TextMatrix(Row%, Col%) = .TextMatrix(Row%, Col% - 1)
  315.         Next Col%
  316.     Next Row%
  317.     For Row% = 1 To .Rows - 1       'clear all cells in this col
  318.         .TextMatrix(Row%, C%) = ""
  319.     Next Row%
  320. End With
  321. End Sub
  322. Private Sub MnuFGridExtrRow_Click()
  323. Dim Row%, R%, C%
  324. With FG1
  325.     If .Rows > 2 Then        'make sure we don't del row 1
  326.         Row% = .Row
  327.         For R% = 1 To .Cols - 1
  328.             If .TextMatrix(Row%, R%) > "" Then   'data?
  329.                 C% = 1
  330.                 Exit For
  331.             End If
  332.         Next R%
  333.         If C% Then
  334.             R% = MsgBox("There is data in Row" + Str$(Row%) + " ! Delete anyway?", vbYesNo, "Delete Row!")
  335.         End If
  336.         If C% = 0 Or R% = 6 Then        'no exist. data or YES
  337.             For R% = .Row To .Rows - 2      'move exist data up 1 row
  338.                 For C% = 1 To FG1.Cols - 1
  339.                     .TextMatrix(R%, C%) = .TextMatrix(R% + 1, C%)
  340.                 Next C%
  341.             Next R%
  342.             If Row% = .Rows - 1 Then    'set new cursor row
  343.                 .Row = .Rows - 2
  344.             End If
  345.             .Rows = .Rows - 1           'delete last row
  346.         End If
  347.     End If
  348. End With
  349. End Sub
  350. Private Sub MnuFGridExtrCol_Click()
  351. Dim Col%, R%, C%
  352. With FG1
  353.     If .Cols > 2 Then        'make sure we don't del col 1
  354.         Col% = .Col
  355.         For R% = 1 To FG1.Rows - 1
  356.             If .TextMatrix(R%, Col%) > "" Then   'data?
  357.                 C% = 1
  358.                 Exit For
  359.             End If
  360.         Next R%
  361.         If C% Then
  362.             R% = MsgBox("There is data in Col" + Str$(Col%) + " ! Delete anyway?", vbYesNo, "Delete Column!")
  363.         End If
  364.         If C% = 0 Or R% = 6 Then    'no exist data or YES
  365.             For R% = 1 To .Rows - 1     'move exist. data left 1 col
  366.                 For C% = Col% To .Cols - 2
  367.                     .TextMatrix(R%, C%) = .TextMatrix(R%, C% + 1)
  368.                 Next C%
  369.             Next R%
  370.             If Col% = .Cols - 1 Then
  371.                 .Col = .Cols - 2
  372.             End If
  373.             .Cols = .Cols - 1           'delete last col
  374.         End If
  375.     End If
  376. End With
  377. End Sub
  378. Private Sub Stop_Click()
  379.     End
  380. End Sub
  381. Private Sub INCR_CELL()                     'advance to next cell
  382. With FG1
  383.     .HighLight = flexHighlightNever         'turn off hi-lite
  384.     If .Col < .Cols - 1 Then
  385.         .Col = .Col + 1
  386.     Else
  387.         If .Row < .Rows - 1 Then
  388.             .Row = .Row + 1                 'down 1 row
  389.             If AutoReturn.Value = 1 Then    'auto return?
  390.                 .Col = 1                    'first column
  391.             End If
  392.         End If
  393.     End If
  394.     If .CellTop + .CellHeight > .Top + .Height Then
  395.         .TopRow = .TopRow + 1               'make sure row is visible
  396.     End If
  397.     .HighLight = flexHighlightAlways        'turn on hi-lite
  398. End With
  399. End Sub
  400. 'this sub scrolls the cols / rows if they're not visible! (? why)
  401. Private Sub IsCellVisible()
  402.     Dim a As Boolean
  403.     a = FG1.CellTop
  404. End Sub
  405.