home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch07 / flexgrid / flexgrid.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-02-20  |  11.9 KB  |  424 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  4. Begin VB.Form Form1 
  5.    Caption         =   "FlexGrid"
  6.    ClientHeight    =   5700
  7.    ClientLeft      =   165
  8.    ClientTop       =   735
  9.    ClientWidth     =   8475
  10.    FillStyle       =   2  'Horizontal Line
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5700
  13.    ScaleWidth      =   8475
  14.    StartUpPosition =   3  'Windows Default
  15.    Begin VB.TextBox Text1 
  16.       Height          =   285
  17.       Left            =   1545
  18.       TabIndex        =   2
  19.       Top             =   120
  20.       Width           =   4035
  21.    End
  22.    Begin MSFlexGridLib.MSFlexGrid Grid 
  23.       Height          =   5055
  24.       Left            =   120
  25.       TabIndex        =   0
  26.       Top             =   480
  27.       Width           =   8175
  28.       _ExtentX        =   14420
  29.       _ExtentY        =   8916
  30.       _Version        =   327680
  31.       Rows            =   100
  32.       Cols            =   100
  33.       BackColor       =   16777215
  34.       ForeColorSel    =   -2147483628
  35.       FocusRect       =   2
  36.       MergeCells      =   4
  37.       AllowUserResizing=   1
  38.    End
  39.    Begin MSComDlg.CommonDialog CommonDialog1 
  40.       Left            =   8130
  41.       Top             =   -30
  42.       _ExtentX        =   847
  43.       _ExtentY        =   847
  44.       _Version        =   327680
  45.       FontSize        =   1.17491e-38
  46.    End
  47.    Begin VB.Label Label1 
  48.       BorderStyle     =   1  'Fixed Single
  49.       Height          =   285
  50.       Left            =   120
  51.       TabIndex        =   1
  52.       Top             =   120
  53.       Width           =   5475
  54.    End
  55.    Begin VB.Menu FileMenu 
  56.       Caption         =   "File"
  57.       Begin VB.Menu FileNew 
  58.          Caption         =   "New"
  59.       End
  60.       Begin VB.Menu FileOpen 
  61.          Caption         =   "Open"
  62.       End
  63.       Begin VB.Menu FileSave 
  64.          Caption         =   "Save"
  65.       End
  66.       Begin VB.Menu FileSaveAs 
  67.          Caption         =   "Save As"
  68.       End
  69.       Begin VB.Menu FileExit 
  70.          Caption         =   "Exit"
  71.       End
  72.    End
  73.    Begin VB.Menu EditMenu 
  74.       Caption         =   "Edit"
  75.       Begin VB.Menu EditCopy 
  76.          Caption         =   "Copy"
  77.       End
  78.       Begin VB.Menu EditCut 
  79.          Caption         =   "Cut"
  80.       End
  81.       Begin VB.Menu EditPaste 
  82.          Caption         =   "Paste"
  83.       End
  84.       Begin VB.Menu EditClear 
  85.          Caption         =   "Clear"
  86.       End
  87.       Begin VB.Menu EditSelect 
  88.          Caption         =   "Select All"
  89.       End
  90.    End
  91.    Begin VB.Menu FormatMenu 
  92.       Caption         =   "Format"
  93.       Begin VB.Menu FormatFont 
  94.          Caption         =   "Font"
  95.       End
  96.       Begin VB.Menu FormatCellColor 
  97.          Caption         =   "CellColor"
  98.       End
  99.       Begin VB.Menu Separator2 
  100.          Caption         =   "-"
  101.       End
  102.       Begin VB.Menu FormatInteger 
  103.          Caption         =   "###"
  104.       End
  105.       Begin VB.Menu Format2decimal 
  106.          Caption         =   "###.00"
  107.       End
  108.       Begin VB.Menu FormatComaInteger 
  109.          Caption         =   "#,###.00"
  110.       End
  111.       Begin VB.Menu FormatDollar 
  112.          Caption         =   "$#,###.00"
  113.       End
  114.    End
  115.    Begin VB.Menu MergeMenu 
  116.       Caption         =   "Merge"
  117.       Begin VB.Menu MergeFree 
  118.          Caption         =   "Free Merge"
  119.       End
  120.       Begin VB.Menu MergeRows 
  121.          Caption         =   "Merge Rows"
  122.       End
  123.       Begin VB.Menu MergeCols 
  124.          Caption         =   "Merge Columns"
  125.       End
  126.       Begin VB.Menu MergeBoth 
  127.          Caption         =   "Merge Both"
  128.       End
  129.       Begin VB.Menu MergeNone 
  130.          Caption         =   "Do not Merge"
  131.       End
  132.    End
  133.    Begin VB.Menu SortMenu 
  134.       Caption         =   "Sort"
  135.       Begin VB.Menu SortAsc 
  136.          Caption         =   "Ascending"
  137.          Begin VB.Menu AscNumeric 
  138.             Caption         =   "Numeric"
  139.          End
  140.          Begin VB.Menu AscString 
  141.             Caption         =   "String"
  142.             Begin VB.Menu AscStringSensitive 
  143.                Caption         =   "Case Sensitive"
  144.             End
  145.             Begin VB.Menu AscStringNonsensitive 
  146.                Caption         =   "case insensitive"
  147.             End
  148.          End
  149.          Begin VB.Menu AscGeneric 
  150.             Caption         =   "All"
  151.          End
  152.       End
  153.       Begin VB.Menu SortDesc 
  154.          Caption         =   "Descending"
  155.          Begin VB.Menu DescNumeric 
  156.             Caption         =   "Numeric"
  157.          End
  158.          Begin VB.Menu DescString 
  159.             Caption         =   "String"
  160.             Begin VB.Menu DescStringSensitive 
  161.                Caption         =   "Case Sensitive"
  162.             End
  163.             Begin VB.Menu DescStringNonSensitive 
  164.                Caption         =   "case insensitive"
  165.             End
  166.          End
  167.          Begin VB.Menu DescGeneric 
  168.             Caption         =   "All"
  169.          End
  170.       End
  171.    End
  172.    Begin VB.Menu AlignMenu 
  173.       Caption         =   "Align"
  174.       Begin VB.Menu AlignLeft 
  175.          Caption         =   "Align Left"
  176.       End
  177.       Begin VB.Menu AlignCenter 
  178.          Caption         =   "Center"
  179.       End
  180.       Begin VB.Menu AlignRight 
  181.          Caption         =   "Align Right"
  182.       End
  183.    End
  184. Attribute VB_Name = "Form1"
  185. Attribute VB_GlobalNameSpace = False
  186. Attribute VB_Creatable = False
  187. Attribute VB_PredeclaredId = True
  188. Attribute VB_Exposed = False
  189. Option Explicit
  190. Dim OpenFile As String
  191. Sub NumberCells()
  192. Dim i As Integer
  193.     For i = 1 To Grid.Rows - 1
  194.         Grid.TextMatrix(0, i) = Format$(i, "000")
  195.     Next
  196.     For i = 1 To Grid.Cols - 1
  197.         Grid.TextMatrix(i, 0) = " " & Format$(i, "000")
  198.     Next
  199. End Sub
  200. Sub FormatCells(formatString)
  201. Dim irow, icol As Integer
  202.     For irow = Grid.Row To Grid.RowSel
  203.         For icol = Grid.Col To Grid.ColSel
  204.             Grid.TextMatrix(irow, icol) = Format$(Grid.TextMatrix(irow, icol), formatString)
  205.         Next
  206.     Next
  207. End Sub
  208. Private Sub AlignCenter_Click()
  209.     Grid.FillStyle = flexFillRepeat
  210.     Grid.CellAlignment = 4
  211.     Grid.FillStyle = flexFillSingle
  212. End Sub
  213. Private Sub AlignLeft_Click()
  214.     Grid.FillStyle = flexFillRepeat
  215.     Grid.CellAlignment = 1
  216.     Grid.FillStyle = flexFillSingle
  217. End Sub
  218. Private Sub AlignRight_Click()
  219.     Grid.FillStyle = flexFillRepeat
  220.     Grid.CellAlignment = 7
  221.     Grid.FillStyle = flexFillSingle
  222. End Sub
  223. Private Sub AscGeneric_Click()
  224.     Grid.Sort = 1
  225. End Sub
  226. Private Sub AscNumeric_Click()
  227.     Grid.Sort = 3
  228. End Sub
  229. Private Sub AscStringNonsensitive_Click()
  230.     Grid.Sort = 5
  231. End Sub
  232. Private Sub AscStringSensitive_Click()
  233.     Grid.Sort = 7
  234. End Sub
  235. Private Sub DescGeneric_Click()
  236.     Grid.Sort = 2
  237. End Sub
  238. Private Sub DescNumeric_Click()
  239.     Grid.Sort = 4
  240. End Sub
  241. Private Sub DescStringNonSensitive_Click()
  242.     Grid.Sort = 6
  243. End Sub
  244. Private Sub DescStringSensitive_Click()
  245.     Grid.Sort = 8
  246. End Sub
  247. Private Sub EditClear_Click()
  248.     Grid.Clip = ""
  249. End Sub
  250. Private Sub EditCopy_Click()
  251. Dim tmpText As String
  252.     tmpText = Grid.Clip
  253.     Clipboard.Clear
  254.     Clipboard.Clear
  255.     Clipboard.SetText tmpText
  256.       
  257. End Sub
  258. Private Sub EditCut_Click()
  259. Dim tmpText As String
  260.     tmpText = Grid.Clip
  261.     Clipboard.Clear
  262.     Clipboard.Clear
  263.     Clipboard.SetText tmpText
  264.     Grid.Clip = ""
  265. End Sub
  266. Private Sub EditPaste_Click()
  267. Dim tmpText As String
  268.     tmpText = Clipboard.GetText
  269.     Grid.Clip = tmpText
  270. End Sub
  271. Private Sub EditSelect_Click()
  272.     Grid.Row = 1
  273.     Grid.Col = 1
  274.     Grid.RowSel = Grid.Rows - 1
  275.     Grid.ColSel = Grid.Cols - 1
  276. End Sub
  277. Private Sub FileNew_Click()
  278.     Grid.Clear
  279. End Sub
  280. Private Sub FileOpen_Click()
  281. Dim allCells As String
  282. Dim fnum As Integer
  283. Dim curRow, curCol As Integer
  284.     CommonDialog1.DefaultExt = "GDT"
  285.     CommonDialog1.Action = 1
  286.     If CommonDialog1.filename = "" Then Exit Sub
  287.     fnum = FreeFile
  288.     Open CommonDialog1.filename For Input As #fnum
  289.     Input #fnum, allCells
  290.     EditSelect_Click
  291.     Grid.Clip = allCells
  292.     Close #fnum
  293.     Grid.Row = 1
  294.     Grid.Col = 1
  295.     Grid.RowSel = Grid.Row
  296.     Grid.ColSel = Grid.Col
  297.     NumberCells
  298. End Sub
  299. Private Sub FileSave_Click()
  300. Dim allCells As String
  301. Dim fnum As Integer
  302. Dim curRow, curCol As Integer
  303.     curRow = Grid.Row
  304.     curCol = Grid.Col
  305.     CommonDialog1.DefaultExt = "GDT"
  306.     CommonDialog1.Action = 2
  307.     If CommonDialog1.filename = "" Then Exit Sub
  308.     EditSelect_Click
  309.     allCells = Grid.Clip
  310.     fnum = FreeFile
  311.     Open CommonDialog1.filename For Output As #fnum
  312.     Write #fnum, allCells
  313.     Close #fnum
  314.     Grid.Row = curRow
  315.     Grid.Col = curCol
  316.     Grid.RowSel = Grid.Row
  317.     Grid.ColSel = Grid.Col
  318. End Sub
  319. Private Sub Form_Load()
  320.     NumberCells
  321. End Sub
  322. Private Sub Format2decimal_Click()
  323.     FormatCells ("###.00")
  324. End Sub
  325. Private Sub FormatCellColor_Click()
  326.     CommonDialog1.ShowColor
  327.     Grid.FillStyle = flexFillRepeat
  328.     Grid.CellBackColor = CommonDialog1.Color
  329.     Grid.FillStyle = flexFillSingle
  330. End Sub
  331. Private Sub FormatComaInteger_Click()
  332.     FormatCells ("#,###.00")
  333. End Sub
  334. Private Sub FormatDollar_Click()
  335.     FormatCells ("$#,###.00")
  336. End Sub
  337. Private Sub FormatFont_Click()
  338. On Error Resume Next
  339.     CommonDialog1.Flags = cdlCFBoth
  340.     CommonDialog1.ShowFont
  341.     Grid.FillStyle = flexFillRepeat
  342.     Grid.CellFontName = CommonDialog1.FontName
  343.     Grid.CellFontBold = CommonDialog1.FontBold
  344.     Grid.CellFontItalic = CommonDialog1.FontItalic
  345.     Grid.CellFontSize = CommonDialog1.FontSize
  346.     Grid.FillStyle = flexFillSingle
  347. End Sub
  348. Private Sub FormatInteger_Click()
  349.     FormatCells ("###")
  350. End Sub
  351. Private Sub Grid_Click()
  352.     Label1.Caption = Grid.TextMatrix(Grid.Col, 0) & " : " & Grid.TextMatrix(0, Grid.Row)
  353.     Text1.Text = Grid.Text
  354.     Text1.SetFocus
  355. End Sub
  356. Private Sub Grid_EnterCell()
  357. On Error Resume Next
  358.     Text1.Text = Grid.Text
  359.     Text1.SetFocus
  360.     Text1.SelStart = 0
  361.     Text1.SelLength = Len(Text1.Text)
  362. End Sub
  363. Private Sub Grid_LeaveCell()
  364.     Grid.Text = Text1.Text
  365. End Sub
  366. Private Sub MergeBoth_Click()
  367. Dim irow, icol As Integer
  368.     For irow = Grid.Row To Grid.RowSel
  369.         Grid.MergeRow(irow) = True
  370.     Next
  371.     Grid.MergeCells = 4
  372.     For icol = Grid.Col To Grid.ColSel
  373.         Grid.MergeCol(icol) = True
  374.     Next
  375.     Grid.MergeCells = 4
  376. End Sub
  377. Private Sub MergeCols_Click()
  378. Dim icol As Integer
  379.     For icol = Grid.Col To Grid.ColSel
  380.         Grid.MergeCol(icol) = True
  381.     Next
  382.     Grid.MergeCells = 3
  383. End Sub
  384. Private Sub MergeFree_Click()
  385. Dim irow, icol As Integer
  386.     For irow = Grid.Row To Grid.RowSel
  387.         Grid.MergeRow(irow) = True
  388.     Next
  389.     For icol = Grid.Col To Grid.ColSel
  390.         Grid.MergeCol(icol) = True
  391.     Next
  392.     Grid.MergeCells = 1
  393.         
  394. End Sub
  395. Private Sub MergeNone_Click()
  396.     Grid.MergeCells = 0
  397. End Sub
  398. Private Sub MergeRows_Click()
  399. Dim irow As Integer
  400.     For irow = Grid.Row To Grid.RowSel
  401.         Grid.MergeRow(irow) = True
  402.     Next
  403.     Grid.MergeCells = 2
  404. End Sub
  405. Private Sub Text1_KeyPress(KeyAscii As Integer)
  406. Dim SRow, SCol As Integer
  407.     If KeyAscii = 13 Then
  408.         Grid.Text = Text1.Text
  409.         SRow = Grid.Row + 1
  410.         SCol = Grid.ColSel
  411.         If SRow = Grid.Rows Then
  412.             SRow = Grid.FixedCols
  413.             If SCol < Grid.Cols - Grid.FixedCols Then SCol = SCol + 1
  414.         End If
  415.         Grid.Row = SRow
  416.         Grid.Col = SCol
  417.         Grid.RowSel = SRow
  418.         Grid.ColSel = SCol
  419.         Text1.Text = Grid.Text
  420.         Text1.SetFocus
  421.         KeyAscii = 0
  422.     End If
  423. End Sub
  424.