home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Enterprise21341411142008.psc / MSFlexGrd / frmFlex.frm next >
Text File  |  2008-11-13  |  11KB  |  396 lines

  1. VERSION 5.00
  2. Object = "{0ECD9B60-23AA-11D0-B351-00A0C9055D8E}#6.0#0"; "MSHFLXGD.OCX"
  3. Begin VB.Form frmFlex 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Hierarchical FlexGrid Sample"
  6.    ClientHeight    =   5850
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   8235
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   5850
  14.    ScaleWidth      =   8235
  15.    Begin VB.TextBox txtEdit 
  16.       BorderStyle     =   0  'None
  17.       Height          =   315
  18.       Left            =   1290
  19.       TabIndex        =   7
  20.       Top             =   915
  21.       Visible         =   0   'False
  22.       Width           =   1650
  23.    End
  24.    Begin VB.PictureBox Picture1 
  25.       Align           =   2  'Align Bottom
  26.       BorderStyle     =   0  'None
  27.       Height          =   675
  28.       Left            =   0
  29.       ScaleHeight     =   675
  30.       ScaleWidth      =   8235
  31.       TabIndex        =   2
  32.       Top             =   5175
  33.       Width           =   8235
  34.       Begin VB.CommandButton cmdClose 
  35.          Caption         =   "Close"
  36.          Height          =   330
  37.          Left            =   4815
  38.          TabIndex        =   8
  39.          Top             =   90
  40.          Width           =   1065
  41.       End
  42.       Begin VB.CommandButton cmdDelete 
  43.          Caption         =   "&Delete"
  44.          Height          =   330
  45.          Left            =   3705
  46.          TabIndex        =   4
  47.          Top             =   90
  48.          Width           =   1035
  49.       End
  50.       Begin VB.CommandButton cmdEdit 
  51.          Caption         =   "&Edit"
  52.          Height          =   330
  53.          Left            =   2580
  54.          TabIndex        =   3
  55.          Top             =   90
  56.          Width           =   1035
  57.       End
  58.       Begin VB.CommandButton cmdUpdate 
  59.          Caption         =   "&Update"
  60.          Height          =   330
  61.          Left            =   2580
  62.          TabIndex        =   6
  63.          Top             =   90
  64.          Width           =   1035
  65.       End
  66.       Begin VB.CommandButton cmdCancel 
  67.          Caption         =   "Cancel"
  68.          Height          =   330
  69.          Left            =   3705
  70.          TabIndex        =   5
  71.          Top             =   90
  72.          Width           =   1035
  73.       End
  74.    End
  75.    Begin MSHierarchicalFlexGridLib.MSHFlexGrid FlxGrid 
  76.       Height          =   4410
  77.       Left            =   135
  78.       TabIndex        =   1
  79.       Top             =   645
  80.       Width           =   7920
  81.       _ExtentX        =   13970
  82.       _ExtentY        =   7779
  83.       _Version        =   393216
  84.       RowHeightMin    =   2
  85.       WordWrap        =   -1  'True
  86.       Redraw          =   0   'False
  87.       AllowBigSelection=   0   'False
  88.       FocusRect       =   2
  89.       HighLight       =   2
  90.       AllowUserResizing=   3
  91.       Appearance      =   0
  92.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  93.          Name            =   "Arial"
  94.          Size            =   9.75
  95.          Charset         =   0
  96.          Weight          =   400
  97.          Underline       =   0   'False
  98.          Italic          =   0   'False
  99.          Strikethrough   =   0   'False
  100.       EndProperty
  101.       BeginProperty FontFixed {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  102.          Name            =   "Arial"
  103.          Size            =   9.75
  104.          Charset         =   0
  105.          Weight          =   700
  106.          Underline       =   0   'False
  107.          Italic          =   0   'False
  108.          Strikethrough   =   0   'False
  109.       EndProperty
  110.       _NumberOfBands  =   1
  111.       _Band(0).Cols   =   2
  112.       _Band(0).GridLinesBand=   1
  113.       _Band(0).TextStyleBand=   0
  114.       _Band(0).TextStyleHeader=   0
  115.    End
  116.    Begin VB.Label lblTitle 
  117.       Alignment       =   2  'Center
  118.       BackColor       =   &H00FFC0C0&
  119.       Caption         =   "Hierarchical FlexGrid  Usage"
  120.       BeginProperty Font 
  121.          Name            =   "Arial"
  122.          Size            =   21.75
  123.          Charset         =   0
  124.          Weight          =   700
  125.          Underline       =   0   'False
  126.          Italic          =   0   'False
  127.          Strikethrough   =   0   'False
  128.       EndProperty
  129.       ForeColor       =   &H00800000&
  130.       Height          =   615
  131.       Left            =   -180
  132.       TabIndex        =   0
  133.       Top             =   -30
  134.       Width           =   8430
  135.    End
  136. End
  137. Attribute VB_Name = "frmFlex"
  138. Attribute VB_GlobalNameSpace = False
  139. Attribute VB_Creatable = False
  140. Attribute VB_PredeclaredId = True
  141. Attribute VB_Exposed = False
  142. Option Explicit
  143. Dim adoPrimaryRS As ADODB.Recordset, iRowData As Long, iColIndex As Long
  144. Dim Cn As ADODB.Connection, I As Long, LastCol As Integer, iSort As Integer
  145. Dim iCellTop As Long, iCellLeft As Long
  146.  
  147. Private Sub cmdCancel_Click()
  148. 'Return the txtEdit to default state
  149. With txtEdit
  150.     .Text = ""
  151.     .Visible = False
  152. End With
  153.  
  154. 'Change buttons .Visible props
  155. SetButtons False
  156.  
  157. End Sub
  158.  
  159. Private Sub cmdClose_Click()
  160. Unload Me
  161. End Sub
  162.  
  163. Private Sub cmdDelete_Click()
  164. On Error Resume Next
  165.  
  166. 'Disable form from getting focus
  167. Me.Enabled = False
  168.  
  169. 'Confirm delete action
  170. If MsgBox("Delete current record?", vbYesNo + vbQuestion + vbDefaultButton2, "Confirm...") = vbNo Then
  171.     Me.Enabled = True
  172.     Exit Sub
  173. End If
  174.  
  175. 'Delete record
  176. With adoPrimaryRS
  177.     .Filter = "RecordID = " & iRowData
  178.     
  179.     .Delete
  180.     
  181.     .Filter = ""
  182.     .MoveFirst
  183.     
  184.     'Remove item from FlexiGrid
  185.     With FlxGrid
  186.         .RemoveItem iRowData
  187.         .Redraw = True
  188.     End With
  189.     
  190. End With
  191.     
  192. Me.Enabled = True
  193.     
  194. End Sub
  195.  
  196. Private Sub cmdEdit_Click()
  197.  
  198. 'Prepare the Edit text box
  199. With txtEdit
  200.  
  201.     'Position the textbox
  202.     .Font = FlxGrid.Font
  203.     .FontSize = FlxGrid.CellFontSize
  204.     .Left = iCellLeft + 150
  205.     .Top = iCellTop
  206.     .Height = FlxGrid.CellHeight
  207.     .Width = FlxGrid.CellWidth
  208.     
  209.     'Get the column index no
  210.     iColIndex = Me.FlxGrid.Col
  211.     
  212.     'Copy column text into text box
  213.     .Text = FlxGrid.Text
  214.     
  215.     'Make it visible and current
  216.     .Visible = True
  217.     .SetFocus
  218.     
  219. End With
  220.  
  221. SetButtons True
  222.  
  223. End Sub
  224. Private Sub SetButtons(bVal As Boolean)
  225. 'This controls some buttons visible & enable properties
  226. cmdCancel.Visible = bVal
  227. cmdDelete.Visible = Not bVal
  228. cmdUpdate.Visible = bVal
  229. cmdEdit.Visible = Not bVal
  230. cmdClose.Visible = Not bVal
  231. FlxGrid.Enabled = Not bVal
  232. End Sub
  233.  
  234. Private Sub cmdUpdate_Click()
  235.  
  236. Dim newValue As Variant
  237. newValue = Me.txtEdit.Text
  238.  
  239. With adoPrimaryRS
  240.     .Filter = "RecordID = " & iRowData
  241.     .MoveFirst
  242.     iColIndex = iColIndex - 1
  243.     .Fields(iColIndex).Value = newValue
  244.     .Update
  245.     .Filter = ""
  246.     .Requery
  247.     
  248.     With FlxGrid
  249.         Set .DataSource = Nothing
  250.         GridCols
  251.         .Redraw = True
  252.     End With
  253.     
  254.      
  255. End With
  256. cmdCancel_Click
  257. End Sub
  258.  
  259. Private Sub FlxGrid_Click()
  260. With Me.FlxGrid
  261.     iRowData = .RowData(FlxGrid.RowSel)
  262.     iCellTop = .CellTop + Me.FlxGrid.Top
  263.     iCellLeft = .CellLeft
  264. End With
  265.  
  266. End Sub
  267.  
  268. Private Sub FlxGrid_DblClick()
  269. DoSort
  270. End Sub
  271.  
  272. Private Sub Form_Load()
  273. On Error GoTo FormLoad_Err
  274.  
  275. Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
  276.  
  277. Dim strDB As String, RecCount As Long
  278. strDB = App.Path & "\Manager.mdb"
  279.  
  280. Set Cn = New Connection
  281.   With Cn
  282.     .CursorLocation = adUseClient
  283.     .ConnectionTimeout = 10
  284.     .Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & strDB
  285.   End With
  286.  
  287. Set adoPrimaryRS = New Recordset
  288. With adoPrimaryRS
  289.     .LockType = adLockOptimistic
  290.     .CursorType = adOpenStatic
  291.     .Source = "select LoadingDate,DepartureDate," _
  292.      & "VehicleDriverName,VehicleConductorName," _
  293.      & "VehicleType,VehicleRegNo," _
  294.      & "VehicleCapacity,ItemLoaded," _
  295.      & "QtyLoaded,WayBillNo," _
  296.      & "VehicleDestination,RecordID from tblVehicleParticulars"
  297.     Set .ActiveConnection = Cn
  298.     .Open
  299.     
  300.     If .RecordCount > 0 Then
  301.         GridCols
  302.     End If
  303.     
  304. End With
  305.  
  306. FlxGrid.Redraw = True
  307.  
  308. FormLoad_Exit:
  309. Exit Sub
  310.   
  311. FormLoad_Err:
  312.     MsgBox "Unexpected Error: " & Err.Description
  313.  
  314.     Resume FormLoad_Exit
  315.     
  316. End Sub
  317. Private Sub GridCols()
  318. Dim strHeader As String, fldCount As Integer
  319. Dim RowDataNum As Long, strRowHeader As String
  320.  
  321. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  322. 'Prepare the Row & Column headers
  323. strHeader = " "
  324.  
  325. strHeader = "     |Loading    |Departure  |Driver Name  |Conductor Name|" _
  326.      & "Vehicle Type|Reg No      |Capacity   |Item Loaded|" _
  327.      & "Qty. Loaded|Way Bill No   |Destination|;"
  328.  
  329. 'strHeader = strHeader & ";"
  330.  
  331. 'Use no of records to enumerate the columns as in Excel
  332. fldCount = adoPrimaryRS.RecordCount
  333. strRowHeader = ""
  334. For I = 1 To fldCount
  335.     strRowHeader = strRowHeader & "          |" & CStr(I)
  336. Next
  337.  
  338. strHeader = strHeader & strRowHeader
  339. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  340.  
  341. 'Set FlxGrid.RowData for editing/deleting purposes
  342. 'using the RecordID field entry as RowData
  343. With FlxGrid
  344.  
  345.     .Redraw = False
  346.     Set .DataSource = adoPrimaryRS
  347.     adoPrimaryRS.MoveFirst
  348.     
  349.     For I = FlxGrid.FixedRows To FlxGrid.Rows - 1
  350.         If adoPrimaryRS.EOF Then Exit Sub
  351.         RowDataNum = adoPrimaryRS!RecordID
  352.         FlxGrid.RowData(I) = RowDataNum
  353.         adoPrimaryRS.MoveNext
  354.     Next
  355.     
  356.     'Apply header
  357.     .FormatString = strHeader
  358.     .Redraw = True
  359.     .Refresh
  360. End With
  361.  
  362. End Sub
  363. Sub DoSort()
  364. 'Sort the columns based on clicked column index
  365. On Error Resume Next
  366. Dim iCol As Integer, iBandColIndex As Integer
  367.  
  368.     Dim strSort As String
  369.     With FlxGrid
  370.         iBandColIndex = .BandColIndex
  371.         iCol = .Col         'Get clicked column index
  372.         strSort = .DataField(0, iBandColIndex)  'Get the associated data field
  373.        
  374.         If LastCol = iCol Then  'Same column clicked
  375.         
  376.              If iSort = 1 Then  'Last Sort = Ascending
  377.                 .Sort = 2       'Now Sort Descending
  378.                 iSort = 2
  379.              ElseIf iSort = 2 Then  'Last Sort = Descending
  380.                 .Sort = 1           'Now Sort Ascending
  381.                 iSort = 1
  382.             End If
  383.             
  384.         ElseIf LastCol <> iCol Then  'New column clicked
  385.             .Sort = 1                'Sort Ascending
  386.             iSort = 1
  387.         End If
  388.     
  389.     End With
  390.     
  391.     LastCol = iCol  'Store the index of last column clicked
  392.     
  393. End Sub
  394.  
  395.  
  396.