home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / TEMPLATE / FORMS / DATAGRID.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-17  |  6.9 KB  |  229 lines

  1. VERSION 5.00
  2. Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
  3. Begin VB.Form frmDataGrid 
  4.    ClientHeight    =   4590
  5.    ClientLeft      =   1650
  6.    ClientTop       =   1545
  7.    ClientWidth     =   6150
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4590
  10.    ScaleMode       =   0  'User
  11.    ScaleWidth      =   6150
  12.    Begin VB.PictureBox picButtons 
  13.       Align           =   1  'Align Top
  14.       Appearance      =   0  'Flat
  15.       BorderStyle     =   0  'None
  16.       ForeColor       =   &H80000008&
  17.       Height          =   330
  18.       Left            =   0
  19.       ScaleHeight     =   330
  20.       ScaleWidth      =   6150
  21.       TabIndex        =   1
  22.       TabStop         =   0   'False
  23.       Top             =   0
  24.       Width           =   6150
  25.       Begin VB.CommandButton cmdClose 
  26.          Caption         =   "
  27. (&C)"
  28.          Height          =   330
  29.          Left            =   4398
  30.          TabIndex        =   5
  31.          Tag             =   "&Close"
  32.          Top             =   0
  33.          Width           =   1437
  34.       End
  35.       Begin VB.CommandButton cmdFilter 
  36.          Caption         =   "
  37. (&F)"
  38.          Height          =   330
  39.          Left            =   2924
  40.          TabIndex        =   4
  41.          Tag             =   "&Filter"
  42.          Top             =   0
  43.          Width           =   1462
  44.       End
  45.       Begin VB.CommandButton cmdSort 
  46.          Caption         =   "
  47. (&S)"
  48.          Height          =   330
  49.          Left            =   1462
  50.          TabIndex        =   3
  51.          Tag             =   "&Sort"
  52.          Top             =   0
  53.          Width           =   1462
  54.       End
  55.       Begin VB.CommandButton cmdRefresh 
  56.          Caption         =   "
  57. (&R)"
  58.          Height          =   330
  59.          Left            =   0
  60.          TabIndex        =   2
  61.          Tag             =   "&Refresh"
  62.          Top             =   0
  63.          Width           =   1462
  64.       End
  65.    End
  66.    Begin VB.Data Data1 
  67.       Caption         =   "Data1"
  68.       Connect         =   "Access"
  69.       DatabaseName    =   ""
  70.       DefaultCursorType=   0  'DefaultCursor
  71.       DefaultType     =   2  'UseODBC
  72.       Exclusive       =   0   'False
  73.       Height          =   300
  74.       Left            =   2505
  75.       Options         =   0
  76.       ReadOnly        =   0   'False
  77.       RecordsetType   =   1  'Dynaset
  78.       RecordSource    =   ""
  79.       Top             =   2175
  80.       Visible         =   0   'False
  81.       Width           =   1140
  82.    End
  83.    Begin MSDBGrid.DBGrid grdDataGrid 
  84.       Align           =   1  'Align Top
  85.       Bindings        =   "datagrid.frx":0000
  86.       Height          =   3645
  87.       Left            =   0
  88.       OleObjectBlob   =   "datagrid.frx":00CE
  89.       TabIndex        =   0
  90.       Top             =   330
  91.       Width           =   6150
  92.    End
  93. Attribute VB_Name = "frmDataGrid"
  94. Attribute VB_GlobalNameSpace = False
  95. Attribute VB_Creatable = False
  96. Attribute VB_PredeclaredId = True
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99. Dim msSortCol As String
  100. Dim mbCtrlKey As Integer
  101. Sub cmdClose_Click()
  102.     Unload Me
  103. End Sub
  104. Private Sub cmdFilter_Click()
  105.     On Error GoTo FilterErr
  106.     Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  107.     Dim sFilterStr As String
  108.     If Data1.RecordsetType = vbRSTypeTable Then
  109.         Beep
  110.         MsgBox "
  111. ", 48
  112.         Exit Sub
  113.     End If
  114.     Set recRecordset1 = Data1.Recordset                        '
  115.     sFilterStr = InputBox("
  116.     If Len(sFilterStr) = 0 Then Exit Sub
  117.     Screen.MousePointer = vbHourglass
  118.     recRecordset1.Filter = sFilterStr
  119.     Set recRecordset2 = recRecordset1.OpenRecordset(recRecordset1.Type) '
  120.     Set Data1.Recordset = recRecordset2                        '
  121.     Screen.MousePointer = vbDefault
  122.     Exit Sub
  123. FilterErr:
  124.     Screen.MousePointer = vbDefault
  125.     MsgBox "
  126. " & Err & "
  127. " & Err.Description
  128. End Sub
  129. Private Sub cmdRefresh_Click()
  130.     On Error GoTo RefErr
  131.     Data1.Recordset.Requery
  132.     Exit Sub
  133. RefErr:
  134.     MsgBox "
  135. " & Err & "
  136. " & Err.Description
  137. End Sub
  138. Private Sub cmdSort_Click()
  139.     On Error GoTo SortErr
  140.     Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  141.     Dim SortStr As String
  142.     If Data1.RecordsetType = vbRSTypeTable Then
  143.         Beep
  144.         MsgBox "
  145. ", 48
  146.         Exit Sub
  147.     End If
  148.     Set recRecordset1 = Data1.Recordset                        '
  149.     If Len(msSortCol) = 0 Then
  150.         SortStr = InputBox("
  151.         If Len(SortStr) = 0 Then Exit Sub
  152.     Else
  153.         SortStr = msSortCol
  154.     End If
  155.     Screen.MousePointer = vbHourglass
  156.     recRecordset1.Sort = SortStr
  157.     '
  158.     Set recRecordset2 = recRecordset1.OpenRecordset(recRecordset1.Type)
  159.     Set Data1.Recordset = recRecordset2
  160.     Screen.MousePointer = vbDefault
  161.     Exit Sub
  162. SortErr:
  163.     Screen.MousePointer = vbDefault
  164.     MsgBox "
  165. " & Err & "
  166. " & Err.Description
  167. End Sub
  168. Private Sub Form_Load()
  169.     Dim bParmQry As Integer
  170.     Dim qdfTmp As QueryDef
  171.     On Error GoTo LoadErr
  172.     '
  173.     'gsDatabase 
  174.     '
  175.     Data1.DatabaseName = gsDatabase
  176.     'gsRecordSource 
  177.     '
  178.     Data1.RecordSource = gsRecordsource
  179.     Data1.RecordsetType = 1     '
  180.     Data1.Options = 0
  181.     Data1.Refresh
  182.     If Len(Data1.RecordSource) > 50 Then
  183.         Me.Caption = "SQL 
  184.     Else
  185.         Me.Caption = Data1.RecordSource
  186.     End If
  187.     Exit Sub
  188. LoadErr:
  189.     MsgBox "
  190. " & Err & "
  191. " & Err.Description
  192.     Unload Me
  193. End Sub
  194. Private Sub Form_Resize()
  195.     On Error Resume Next
  196.     If Me.WindowState <> 1 Then
  197.         grdDataGrid.Height = Me.Height - (425 + picButtons.Height)
  198.     End If
  199. End Sub
  200. Private Sub grdDataGrid_BeforeDelete(Cancel As Integer)
  201.     If MsgBox("
  202. ", vbYesNo + vbQuestion) <> vbYes Then
  203.         Cancel = True
  204.     End If
  205. End Sub
  206. Private Sub grdDataGrid_BeforeUpdate(Cancel As Integer)
  207.     If MsgBox("
  208. ", vbYesNo + vbQuestion) <> vbYes Then
  209.         Cancel = True
  210.     End If
  211. End Sub
  212. Private Sub grdDataGrid_HeadClick(ByVal ColIndex As Integer)
  213.     '
  214.     If Data1.RecordsetType = vbRSTypeTable Then Exit Sub
  215.     '
  216.  ctrl 
  217.     If mbCtrlKey Then
  218.         msSortCol = "[" & Data1.Recordset(ColIndex).Name & "] desc"
  219.         mbCtrlKey = 0 '
  220.     Else
  221.         msSortCol = "[" & Data1.Recordset(ColIndex).Name & "]"
  222.     End If
  223.     cmdSort_Click
  224.     msSortCol = vbNullString '
  225. End Sub
  226. Private Sub grdDataGrid_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single)
  227.     mbCtrlKey = Shift
  228. End Sub
  229.