home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / PVb5.0 / VB / SAMPLES / VISDATA / DATAGRID.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-03-12  |  8.4 KB  |  279 lines

  1. VERSION 5.00
  2. Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
  3. Begin VB.Form frmDataGrid 
  4.    ClientHeight    =   4605
  5.    ClientLeft      =   3780
  6.    ClientTop       =   2610
  7.    ClientWidth     =   6180
  8.    HelpContextID   =   2016191
  9.    Icon            =   "DATAGRID.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    LockControls    =   -1  'True
  12.    MDIChild        =   -1  'True
  13.    ScaleHeight     =   4605
  14.    ScaleWidth      =   6180
  15.    ShowInTaskbar   =   0   'False
  16.    Tag             =   "Recordset"
  17.    Begin MSDBGrid.DBGrid grdDataGrid 
  18.       Align           =   1  'Align Top
  19.       Bindings        =   "DATAGRID.frx":014A
  20.       Height          =   3795
  21.       Left            =   0
  22.       OleObjectBlob   =   "DATAGRID.frx":015F
  23.       TabIndex        =   5
  24.       Top             =   330
  25.       Width           =   6180
  26.    End
  27.    Begin VB.Data datDataCtl 
  28.       Align           =   2  'Align Bottom
  29.       Connect         =   "Access"
  30.       DatabaseName    =   ""
  31.       DefaultCursorType=   0  'DefaultCursor
  32.       DefaultType     =   2  'UseODBC
  33.       Exclusive       =   0   'False
  34.       Height          =   345
  35.       Left            =   0
  36.       Options         =   0
  37.       ReadOnly        =   0   'False
  38.       RecordsetType   =   1  'Dynaset
  39.       RecordSource    =   ""
  40.       Top             =   4260
  41.       Width           =   6180
  42.    End
  43.    Begin VB.PictureBox picButtons 
  44.       Align           =   1  'Align Top
  45.       Appearance      =   0  'Flat
  46.       BorderStyle     =   0  'None
  47.       ForeColor       =   &H80000008&
  48.       Height          =   330
  49.       Left            =   0
  50.       ScaleHeight     =   330
  51.       ScaleWidth      =   6180
  52.       TabIndex        =   0
  53.       Top             =   0
  54.       Width           =   6180
  55.       Begin VB.CommandButton cmdRefresh 
  56.          Caption         =   "
  57. (&R)"
  58.          Height          =   330
  59.          Left            =   0
  60.          MaskColor       =   &H00000000&
  61.          TabIndex        =   4
  62.          Top             =   0
  63.          Width           =   1455
  64.       End
  65.       Begin VB.CommandButton cmdFilter 
  66.          Caption         =   "
  67. (&F)"
  68.          Height          =   330
  69.          Left            =   2880
  70.          MaskColor       =   &H00000000&
  71.          TabIndex        =   3
  72.          Top             =   0
  73.          Width           =   1455
  74.       End
  75.       Begin VB.CommandButton cmdSort 
  76.          Caption         =   "
  77. (&S)"
  78.          Height          =   330
  79.          Left            =   1440
  80.          MaskColor       =   &H00000000&
  81.          TabIndex        =   2
  82.          Top             =   0
  83.          Width           =   1455
  84.       End
  85.       Begin VB.CommandButton cmdClose 
  86.          Cancel          =   -1  'True
  87.          Caption         =   "
  88. (&C)"
  89.          Height          =   330
  90.          Left            =   4320
  91.          MaskColor       =   &H00000000&
  92.          TabIndex        =   1
  93.          Top             =   0
  94.          Width           =   1440
  95.       End
  96.    End
  97. Attribute VB_Name = "frmDataGrid"
  98. Attribute VB_GlobalNameSpace = False
  99. Attribute VB_Creatable = False
  100. Attribute VB_PredeclaredId = True
  101. Attribute VB_Exposed = False
  102. Option Explicit
  103. '>>>>>>>>>>>>>>>>>>>>>>>>
  104. Const BUTTON1 = "
  105. (&R)"
  106. Const BUTTON2 = "
  107. (&S)"
  108. Const BUTTON3 = "
  109. (&F)"
  110. Const BUTTON4 = "
  111. (&C)"
  112. Const DATACTL = "
  113. Const MSG1 = "
  114. Const MSG2 = "
  115. Const MSG3 = "
  116. Const MSG4 = "
  117. Const MSG5 = "
  118. Const MSG6 = "
  119. Const MSG7 = "
  120. Const MSG8 = "
  121. '>>>>>>>>>>>>>>>>>>>>>>>>
  122. Public mrsFormRecordset As Recordset
  123. Dim msSortCol As String
  124. Dim mbCtrlKey As Integer
  125. Sub cmdClose_Click()
  126.   Unload Me
  127. End Sub
  128. Private Sub cmdFilter_Click()
  129.   On Error GoTo FilterErr
  130.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  131.   Dim sFilterStr As String
  132.   If datDataCtl.RecordsetType = vbRSTypeTable Then
  133.     Beep
  134.     MsgBox MSG1, 48
  135.     Exit Sub
  136.   End If
  137.   Set recRecordset1 = datDataCtl.Recordset            '
  138.   sFilterStr = InputBox(MSG2)
  139.   If Len(sFilterStr) = 0 Then Exit Sub
  140.   Screen.MousePointer = 11
  141.   MsgBar MSG3, True
  142.   recRecordset1.Filter = sFilterStr
  143.   Set recRecordset2 = recRecordset1.OpenRecordset(recRecordset1.Type) '
  144.   Set datDataCtl.Recordset = recRecordset2            '
  145.   Screen.MousePointer = 0
  146.   MsgBar vbNullString, False
  147.   Exit Sub
  148. FilterErr:
  149.   Screen.MousePointer = 0
  150.   MsgBar vbNullString, False
  151.   MsgBox "
  152. " & Err & " " & Error$
  153.   Exit Sub
  154. End Sub
  155. Private Sub cmdRefresh_Click()
  156.   On Error GoTo RefErr
  157.   datDataCtl.Recordset.Requery
  158.   Exit Sub
  159. RefErr:
  160.   MsgBox "
  161. " & Err & " " & Error$
  162.   Exit Sub
  163. End Sub
  164. Private Sub cmdSort_Click()
  165.   On Error GoTo SortErr
  166.   Dim recRecordset1 As Recordset, recRecordset2 As Recordset
  167.   Dim SortStr As String
  168.   If datDataCtl.RecordsetType = vbRSTypeTable Then
  169.     Beep
  170.     MsgBox MSG4, 48
  171.     Exit Sub
  172.   End If
  173.   Set recRecordset1 = datDataCtl.Recordset            '
  174.   If Len(msSortCol) = 0 Then
  175.     SortStr = InputBox(MSG5)
  176.     If Len(SortStr) = 0 Then Exit Sub
  177.   Else
  178.     SortStr = msSortCol
  179.   End If
  180.   Screen.MousePointer = 11
  181.   MsgBar MSG6, True
  182.   recRecordset1.Sort = SortStr
  183.   Set recRecordset2 = recRecordset1.OpenRecordset(recRecordset1.Type)
  184.   Set datDataCtl.Recordset = recRecordset2
  185.   Screen.MousePointer = 0
  186.   MsgBar vbNullString, False
  187.   Exit Sub
  188. SortErr:
  189.   Screen.MousePointer = 0
  190.   MsgBar vbNullString, False
  191.   MsgBox "
  192. " & Err & " " & Error$
  193.   Exit Sub
  194. End Sub
  195. Private Sub datDataCtl_Validate(Action As Integer, Save As Integer)
  196.   If Save Then
  197.     If MsgBox(MSG7, vbYesNo + vbQuestion) <> vbYes Then
  198.       '
  199.       datDataCtl.UpdateControls
  200.     End If
  201.   End If
  202. End Sub
  203. Private Sub Form_Load()
  204.   On Error GoTo LoadErr
  205.   cmdRefresh.Caption = BUTTON1
  206.   cmdSort.Caption = BUTTON2
  207.   cmdFilter.Caption = BUTTON3
  208.   cmdClose.Caption = BUTTON4
  209.   datDataCtl.Caption = DATACTL
  210.   'mrsFormRecordset 
  211.   Set datDataCtl.Recordset = mrsFormRecordset
  212.   Me.Width = 5865
  213.   Me.Height = 5070
  214.   Exit Sub
  215. LoadErr:
  216.   MsgBox "
  217. " & Err & " " & Error$
  218.   Unload Me
  219. End Sub
  220. Private Sub Form_Resize()
  221.   On Error Resume Next
  222.   If Me.WindowState <> vbMinimized Then
  223.     grdDataGrid.Height = Me.ScaleHeight - (picButtons.Height + datDataCtl.Height + 135)
  224.   End If
  225. End Sub
  226. '----------------------------------------------------------
  227.  Data 
  228. '----------------------------------------------------------
  229. Sub datDataCtl_MouseUp(BUTTON As Integer, Shift As Integer, X As Single, Y As Single)
  230.   On Error GoTo DCPErr
  231.   Dim i As Integer
  232.   Dim recClone As Recordset
  233.   Dim sTmpRS As String
  234.   Dim sTmpDB As String
  235.   If BUTTON = 2 Then
  236.     Screen.MousePointer = 11
  237.     sTmpRS = datDataCtl.RecordSource
  238.     sTmpDB = datDataCtl.DatabaseName
  239.     Set gDataCtlObj = datDataCtl
  240.     frmDataCtlProp.Show vbModal
  241.     If Not gDataCtlObj Is Nothing Then
  242.       '
  243.       datDataCtl.Refresh
  244.       If sTmpRS <> gDataCtlObj.RecordSource Or sTmpDB <> gDataCtlObj.DatabaseName Then
  245.         '
  246. data grid
  247.         grdDataGrid.ReBind
  248.       End If
  249.       gbSettingDataCtl = False
  250.     End If
  251.   End If
  252.   Exit Sub
  253. DCPErr:
  254.   MsgBox "
  255. " & Err & " " & Error$
  256.   Unload Me
  257. End Sub
  258. Private Sub grdDataGrid_BeforeDelete(Cancel As Integer)
  259.   If MsgBox(MSG8, vbYesNo + vbQuestion) <> vbYes Then
  260.     Cancel = True
  261.   End If
  262. End Sub
  263. Private Sub grdDataGrid_HeadClick(ByVal ColIndex As Integer)
  264.   If datDataCtl.RecordsetType = vbRSTypeTable Then Exit Sub
  265.   If datDataCtl.Recordset(ColIndex).Type > dbText Then Exit Sub
  266.  ctrl 
  267.   If mbCtrlKey Then
  268.     msSortCol = "[" & datDataCtl.Recordset(ColIndex).Name & "] desc"
  269.     mbCtrlKey = 0 '
  270.   Else
  271.     msSortCol = "[" & datDataCtl.Recordset(ColIndex).Name & "]"
  272.   End If
  273.   cmdSort_Click
  274.   msSortCol = vbNullString '
  275. End Sub
  276. Private Sub grdDataGrid_MouseUp(BUTTON As Integer, Shift As Integer, X As Single, Y As Single)
  277.   mbCtrlKey = Shift
  278. End Sub
  279.