home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / axgrid / axgrid.ctl < prev    next >
Encoding:
Visual Basic user-defined control file  |  1998-12-10  |  115.4 KB  |  3,527 lines

  1. VERSION 5.00
  2. Begin VB.UserControl axgrid 
  3.    ClientHeight    =   4545
  4.    ClientLeft      =   0
  5.    ClientTop       =   0
  6.    ClientWidth     =   7050
  7.    EditAtDesignTime=   -1  'True
  8.    ScaleHeight     =   303
  9.    ScaleMode       =   3  'Pixel
  10.    ScaleWidth      =   470
  11.    ToolboxBitmap   =   "axGrid.ctx":0000
  12.    Begin VB.CommandButton cmdLookup 
  13.       Height          =   330
  14.       Left            =   585
  15.       Picture         =   "axGrid.ctx":0312
  16.       Style           =   1  'Graphical
  17.       TabIndex        =   6
  18.       TabStop         =   0   'False
  19.       Top             =   3735
  20.       Visible         =   0   'False
  21.       Width           =   285
  22.    End
  23.    Begin VB.ListBox List1 
  24.       Appearance      =   0  'Flat
  25.       Height          =   615
  26.       ItemData        =   "axGrid.ctx":078C
  27.       Left            =   1710
  28.       List            =   "axGrid.ctx":078E
  29.       TabIndex        =   5
  30.       Top             =   3465
  31.       Visible         =   0   'False
  32.       Width           =   1185
  33.    End
  34.    Begin VB.PictureBox picSizer 
  35.       Height          =   3855
  36.       Left            =   135
  37.       ScaleHeight     =   3855
  38.       ScaleWidth      =   15
  39.       TabIndex        =   4
  40.       Top             =   45
  41.       Visible         =   0   'False
  42.       Width           =   15
  43.    End
  44.    Begin VB.VScrollBar scrVertical 
  45.       Height          =   4245
  46.       Left            =   6720
  47.       Min             =   1
  48.       TabIndex        =   2
  49.       Top             =   0
  50.       Value           =   1
  51.       Visible         =   0   'False
  52.       Width           =   285
  53.    End
  54.    Begin VB.HScrollBar scrHorizontal 
  55.       Height          =   285
  56.       Left            =   0
  57.       Min             =   1
  58.       TabIndex        =   1
  59.       Top             =   4200
  60.       Value           =   1
  61.       Visible         =   0   'False
  62.       Width           =   6735
  63.    End
  64.    Begin VB.TextBox txtEdit 
  65.       BorderStyle     =   0  'None
  66.       Height          =   195
  67.       Left            =   5160
  68.       TabIndex        =   0
  69.       Top             =   3840
  70.       Visible         =   0   'False
  71.       Width           =   1365
  72.    End
  73.    Begin VB.PictureBox picGrid 
  74.       AutoRedraw      =   -1  'True
  75.       BackColor       =   &H00C0C0C0&
  76.       BorderStyle     =   0  'None
  77.       Height          =   3360
  78.       Left            =   270
  79.       ScaleHeight     =   224
  80.       ScaleMode       =   3  'Pixel
  81.       ScaleWidth      =   388
  82.       TabIndex        =   3
  83.       Top             =   225
  84.       Width           =   5820
  85.    End
  86. End
  87. Attribute VB_Name = "axgrid"
  88. Attribute VB_GlobalNameSpace = False
  89. Attribute VB_Creatable = True
  90. Attribute VB_PredeclaredId = False
  91. Attribute VB_Exposed = True
  92. Attribute VB_Ext_KEY = "PropPageWizardRun" ,"Yes"
  93. Option Base 0
  94.  
  95. Private Const ALIGN_LEFT = 0
  96. Private Const ALIGN_CENTER = 1
  97. Private Const ALIGN_RIGHT = 2
  98.  
  99. Private Const ALIGNV_TOP = 0
  100. Private Const ALIGNV_CENTER = 1
  101. Private Const ALIGNV_BOTTOM = 2
  102.  
  103. Private Const STYLE_NORMAL = 0
  104. Private Const STYLE_BUTTON = 1
  105. Private Const STYLE_EDIT = 2
  106.  
  107. Private Const COLOR_GREY = &HC0C0C0
  108. Private Const COLOR_DARKGREY = &H808080
  109. Private Const m_BorderStyle_Def = 1
  110. Private iBorderStyle As Integer
  111.  
  112. Public Enum axgridBorderStyleEnum
  113.     [No Border] = 0
  114.     [Single] = 1
  115.     [Thin Raised] = 2
  116.     [Thick Raised] = 3
  117.     [Thin Inset] = 4
  118.     [Thick Inset] = 5
  119.     [Etched] = 6
  120.     [Bump] = 7
  121. End Enum
  122.  
  123. Public Enum FixedStyles
  124.   [Flat] = 0
  125.   [3D] = 1
  126. End Enum
  127.  
  128. Public Enum SelectModes
  129.   [SelectionFree] = 0
  130.   [SelectionByRow] = 1
  131.   [SelectionByCol] = 2
  132. End Enum
  133.  
  134. Private sName As String
  135. Private bColSizing As Boolean
  136. Private bRowSizing As Boolean
  137. Private bSizingCol As Boolean
  138. Private bSizingRow As Boolean
  139. Private lTopMargin As Long
  140. Private lLeftMargin As Long
  141. Private lRightMargin As Long
  142. Private lBottomMargin As Long
  143. Private lRow1 As Long
  144. Private lCol1 As Long
  145. Private lRow2 As Long
  146. Private lCol2 As Long
  147. Private bMouseDown As Boolean
  148. Private bEditMode As Boolean
  149. Private bytEvent As Byte
  150. Private lblEvents As Label
  151. Private lCols As Long
  152. Private lRows As Long
  153. Private bColHeader As Boolean
  154. Private bRowHeader As Boolean
  155. Private bShowGrid As Boolean
  156. Private bGridSolid As Boolean
  157. Private lGridLineColor As Long
  158. Private bWidthOverflow As Boolean
  159. Private bHeightOverflow As Boolean
  160. Private bytGridLine As Byte
  161. Private lGridHeight As Long
  162. Private lGridWidth As Long
  163. Private lCol As Long
  164. Private lRow As Long
  165. Private bRedraw As Boolean
  166. Private lLargeVChange As Long
  167. Private lLargeHChange As Long
  168. Private bSelectingCols As Boolean
  169. Private bSelectingRows As Boolean
  170. Private bDAO As Boolean
  171. Private bRDO As Boolean
  172. Private bAutoNewRow As Boolean
  173. Private LookupValues As New Collection
  174. Private m_ListBoxRows As Integer
  175.  
  176. Private lBackColorFixed As Long, lForeColorFixed As Long, lBackColorBkg As Long
  177. 'Private lBackColorSel As Long, lForeColorSel As Long
  178. Private bAllowSelection As Boolean, iFixedStyle As Integer, iSelectionMode As Integer
  179. Private fFont As StdFont, fFontFixed As StdFont, sFormatString As String
  180. Private bAllowUserResizing As Boolean
  181.  
  182. Private lCurrentRowSizer As Long
  183. Private lCurrentColSizer As Long
  184.  
  185. Private Cells As clsCellArray
  186. Private lRowHeight() As Integer
  187. Private lColWidth() As Integer, lColAlign() As Integer, bColEdit() As Boolean
  188. Private lColMask() As Integer
  189. Private hSizers As Collection
  190. Private vSizers As Collection
  191.  
  192. Private lLeftCol As Long
  193. Private lTopRow As Long
  194.  
  195. 'Private Type RECT
  196. '    Left As Long
  197. '    Top As Long
  198. '    Right As Long
  199. '    Bottom As Long
  200. 'End Type
  201.  
  202. 'Private Type POINTAPI
  203. '    x As Long
  204. '    y As Long
  205. 'End Type
  206.  
  207. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Boolean
  208. Private Declare Function SetCursorPos Lib "user32" (ByVal lX As Long, ByVal lY As Long) As Boolean
  209. Private Declare Function InvertRect Lib "user32" (ByVal hDC As Long, lpRect As RECT) As Long
  210. Private Declare Function FrameRect Lib "user32" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  211. Private Declare Function LineTo Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
  212. Private Declare Function MoveToEx Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpPoint As Long) As Long
  213. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  214. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
  215. Private Declare Function FillRect Lib "user32" (ByVal hDC As Long, lpRect As RECT, ByVal hBrush As Long) As Long
  216. Private Declare Function ScrollDC Lib "user32" (ByVal hDC As Long, ByVal dx As Long, ByVal dy As Long, lprcScroll As RECT, lprcClip As RECT, ByVal hrgnUpdate As Long, lprcUpdate As RECT) As Long
  217. Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hDC As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
  218.  
  219. 'kdq090498      added to show focus rectangle instead of black invert
  220. Private Declare Function DrawFocusRect Lib "user32" (ByVal hDC As Long, lpRect As RECT) As Long
  221.  
  222. Private Const DT_BOTTOM = &H8
  223. Private Const DT_CALCRECT = &H400
  224. Private Const DT_CENTER = &H1
  225. Private Const DT_LEFT = &H0
  226. Private Const DT_RIGHT = &H2
  227. Private Const DT_SINGLELINE = &H20
  228. Private Const DT_TOP = &H0
  229. Private Const DT_VCENTER = &H4
  230. Private Const DT_WORDBREAK = &H10
  231.  
  232. 'Flags for DrawFrameControl
  233. Private Const DFC_CAPTION = 1            'Title bar
  234. Private Const DFC_MENU = 2               'Menu
  235. Private Const DFC_SCROLL = 3             'Scroll bar
  236. Private Const DFC_BUTTON = 4             'Standard button
  237.  
  238. Private Const DFCS_CAPTIONCLOSE = &H0    'Close button
  239. Private Const DFCS_CAPTIONMIN = &H1      'Minimize button
  240. Private Const DFCS_CAPTIONMAX = &H2      'Maximize button
  241. Private Const DFCS_CAPTIONRESTORE = &H3  'Restore button
  242. Private Const DFCS_CAPTIONHELP = &H4     'Windows 95 only:
  243.                                          'Help button
  244.  
  245. Private Const DFCS_MENUARROW = &H0       'Submenu arrow
  246. Private Const DFCS_MENUCHECK = &H1       'Check mark
  247. Private Const DFCS_MENUBULLET = &H2      'Bullet
  248. Private Const DFCS_MENUARROWRIGHT = &H4
  249.  
  250. Private Const DFCS_SCROLLUP = &H0               'Up arrow of scroll
  251.                                                 'bar
  252. Private Const DFCS_SCROLLDOWN = &H1             'Down arrow of
  253.                                                 'scroll bar
  254. Private Const DFCS_SCROLLLEFT = &H2             'Left arrow of
  255.                                                 'scroll bar
  256. Private Const DFCS_SCROLLRIGHT = &H3            'Right arrow of
  257.                                                 'scroll bar
  258. Private Const DFCS_SCROLLCOMBOBOX = &H5         'Combo box scroll
  259.                                                 'bar
  260. Private Const DFCS_SCROLLSIZEGRIP = &H8         'Size grip
  261. Private Const DFCS_SCROLLSIZEGRIPRIGHT = &H10   'Size grip in
  262.                                                 'bottom-right
  263.                                                 'corner of window
  264.  
  265. Private Const DFCS_BUTTONCHECK = &H0      'Check box
  266.  
  267. Private Const DFCS_BUTTONRADIO = &H4     'Radio button
  268. Private Const DFCS_BUTTON3STATE = &H8    'Three-state button
  269. Private Const DFCS_BUTTONPUSH = &H10     'Push button
  270.  
  271. Private Const DFCS_INACTIVE = &H100      'Button is inactive
  272.                                          '(grayed)
  273. Private Const DFCS_PUSHED = &H200        'Button is pushed
  274. Private Const DFCS_CHECKED = &H400       'Button is checked
  275.  
  276. Private Const DFCS_ADJUSTRECT = &H2000   'Bounding rectangle is
  277.                                         'adjusted to exclude the
  278.                                         'surrounding edge of the
  279.                                         'push button
  280.  
  281. Private Const DFCS_FLAT = &H4000         'Button has a flat border
  282. Private Const DFCS_MONO = &H8000         'Button has a monochrome
  283.                                          'border
  284.  
  285. Private Declare Function DrawFrameControl Lib "user32" (ByVal hDC&, lpRect As RECT, ByVal un1 As Long, ByVal un2 As Long) As Boolean
  286.  
  287. 'Default Property Values:
  288. Const m_def_Recordset = 0
  289. 'Const m_def_RecordSource = 0
  290. Const m_def_DataSource = 0
  291.  
  292. 'Property Variables:
  293. Dim m_Recordset As Variant
  294. 'Dim m_RecordSource As Variant
  295. Dim m_DataSource As Variant
  296.  
  297. 'Event EnterCell() 'MappingInfo=flxGrid,flxGrid,-1,EnterCell
  298. 'Event LeaveCell() 'MappingInfo=flxGrid,flxGrid,-1,LeaveCell
  299. Event Click() 'MappingInfo=flxGrid,flxGrid,-1,Click
  300. Event DblClick()
  301. Event KeyDown(KeyCode As Integer, Shift As Integer) 'MappingInfo=flxGrid,flxGrid,-1,KeyDown
  302. Attribute KeyDown.VB_MemberFlags = "40"
  303. Event KeyPress(KeyAscii As Integer) 'MappingInfo=flxGrid,flxGrid,-1,KeyPress
  304. Attribute KeyPress.VB_MemberFlags = "40"
  305. Event KeyUp(KeyCode As Integer, Shift As Integer) 'MappingInfo=flxGrid,flxGrid,-1,KeyUp
  306. Attribute KeyUp.VB_MemberFlags = "40"
  307. Event MouseDown(button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=flxGrid,flxGrid,-1,MouseDown
  308. Event MouseMove(button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=flxGrid,flxGrid,-1,MouseMove
  309. Attribute MouseMove.VB_MemberFlags = "40"
  310. Event MouseUp(button As Integer, Shift As Integer, x As Single, y As Single) 'MappingInfo=flxGrid,flxGrid,-1,MouseUp
  311. Attribute MouseUp.VB_MemberFlags = "40"
  312. Event Scroll() 'MappingInfo=flxGrid,flxGrid,-1,Scroll
  313. Event BeforeEdit(Row As Long, Col As Long, Cancel As Boolean)
  314. Attribute BeforeEdit.VB_Description = "Occurs before editing a cell"
  315. Event AfterEdit(Row As Long, Col As Long, NewValue As String)
  316. Attribute AfterEdit.VB_Description = "Occurs after ediing a cell"
  317. Event BeforeAddRow(ByVal Cancel As Boolean)
  318. Attribute BeforeAddRow.VB_Description = "Occurs before adding a new row"
  319. Event AfterAddRow(Row As Long)
  320. Attribute AfterAddRow.VB_Description = "Occurs after adding a row"
  321. Event BeforeDeleteRow(Row As Long, Cancel As Boolean)
  322. Attribute BeforeDeleteRow.VB_Description = "Occurs before deleting a row"
  323. Event AfterDeleteRow(Row As Long)
  324. Attribute AfterDeleteRow.VB_Description = "Occurs after deleting a row"
  325.  
  326. Public Property Get Rows() As Long
  327. Attribute Rows.VB_Description = "Sets/gets the total number of rows in the grid"
  328.  
  329.     Rows = lRows
  330. End Property
  331.  
  332. Public Property Let Rows(lNewValue As Long)
  333.  
  334.     scrVertical.Max = lNewValue
  335.     InitializeRows lNewValue&
  336.     lRows = lNewValue
  337.     Refresh
  338. End Property
  339.  
  340. Public Property Get Cols() As Long
  341. Attribute Cols.VB_Description = "Gets/sets the total number of columns in the grid"
  342.     Cols = lCols
  343. End Property
  344.  
  345. Public Property Let Cols(lNewValue As Long)
  346.  
  347.     scrHorizontal.Max = lNewValue
  348.     InitializeCols lNewValue
  349.     lCols = lNewValue
  350.     Refresh
  351. End Property
  352.  
  353. Public Sub Refresh()
  354.  
  355.     Dim lThisRow As Long, lThisCol As Long
  356.     Dim lMyColWidth As Long, lMyRowHeight As Long
  357.     Dim lpRect As RECT
  358.     Dim lScaleHeight As Long, lScaleWidth As Long
  359.     
  360.     If bRedraw = False Then Exit Sub
  361.     
  362.     picGrid.Cls
  363.     If bShowGrid Then
  364.         bytGridLine = 1
  365.     Else
  366.         bytGridLine = 0
  367.     End If
  368.     
  369.     lScaleHeight = picGrid.ScaleHeight
  370.     lScaleWidth = picGrid.ScaleWidth
  371.     
  372.     'Draw all the cells that will fit in the viewport
  373.     RedrawAllCells True
  374.     
  375.     'Draw the vertical scroll bar (if necessary)
  376.     If bHeightOverflow Then
  377.         If bWidthOverflow = False Then          'kdq090898      changed so scrollbars size properly
  378.           scrVertical.Height = lScaleHeight
  379.         Else
  380.           scrVertical.Height = lScaleHeight - scrHorizontal.Height
  381.         End If
  382.         scrVertical.Visible = True
  383.         scrVertical.Tag = True
  384.     Else
  385.         scrVertical.Visible = False
  386.         scrVertical.Tag = False
  387.     End If
  388.     
  389.     'Draw the horizontal scroll bar (if necessary)
  390.     If bWidthOverflow Then
  391.         If bHeightOverflow = False Then         'kdq090898      changed so scrollbars size properly
  392.           scrHorizontal.Width = lScaleWidth
  393.         Else
  394.           scrHorizontal.Width = lScaleWidth - scrVertical.Width
  395.         End If
  396.         scrHorizontal.Visible = True
  397.         scrHorizontal.Tag = True
  398.     Else
  399.         scrHorizontal.Visible = False
  400.         scrHorizontal.Tag = False
  401.     End If
  402.  
  403.     'Draw the grid border
  404.     'lpRect.Left = 0
  405.     'lpRect.Top = 0
  406.     'lpRect.Bottom = lScaleHeight
  407.     'lpRect.Right = 0
  408.     'DrawLine lpRect, vbBlack
  409.     '
  410.     'lpRect.Right = lScaleWidth
  411.     'lpRect.Bottom = 0
  412.     'DrawLine lpRect, vbBlack
  413. End Sub
  414.  
  415. Private Sub DrawButton(x As Long, y As Long, lWidth As Long, lHeight As Long, Value As Integer)
  416.  
  417.     Dim lpRect As RECT
  418.     
  419.     If Value Then
  420.         un2 = DFCS_BUTTONPUSH Or DFCS_PUSHED
  421.     Else
  422.         un2 = DFCS_BUTTONPUSH
  423.     End If
  424.  
  425.     '**********************  Draw the button  ****************************
  426.     un1 = DFC_BUTTON
  427.     lpRect.Left = x
  428.     lpRect.Top = y
  429.     lpRect.Right = x + lWidth
  430.     lpRect.Bottom = y + lHeight
  431.     
  432.     DrawBox x, y, lWidth, lHeight, COLOR_GREY                 'kdq090198  clear out center of button
  433.     
  434.     Select Case Value
  435.         Case False
  436.             di = DrawEdge(picGrid.hDC, lpRect, BDR_RAISEDINNER, BF_TOPLEFT)
  437.             di = DrawEdge(picGrid.hDC, lpRect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT)
  438.         Case True
  439.             di = DrawEdge(picGrid.hDC, lpRect, BDR_SUNKENINNER, BF_TOPLEFT)
  440.             di = DrawEdge(picGrid.hDC, lpRect, BDR_SUNKENOUTER, BF_BOTTOMRIGHT)
  441.      End Select
  442. End Sub
  443.  
  444. Public Property Get ColHeader() As Boolean
  445. Attribute ColHeader.VB_Description = "Determines if column headers are displayed"
  446.     ColHeader = bColHeader
  447. End Property
  448.  
  449. Public Property Let ColHeader(bNewValue As Boolean)
  450.     bColHeader = bNewValue
  451.     Refresh
  452.     PropertyChanged "ColHeader"
  453. End Property
  454.  
  455. Public Property Get RowHeader() As Boolean
  456. Attribute RowHeader.VB_Description = "Determines if row headers are displayed"
  457.     RowHeader = bRowHeader
  458. End Property
  459.  
  460. Public Property Let RowHeader(bNewValue As Boolean)
  461.     bRowHeader = bNewValue
  462.     Refresh
  463.     PropertyChanged "RowHeader"
  464. End Property
  465.  
  466. Public Property Get CellBackColor(lThisCol As Long, lThisRow As Long) As Long
  467. Attribute CellBackColor.VB_MemberFlags = "440"
  468.     CellBackColor = Cells.BackColor(lThisCol, lThisRow)
  469. End Property
  470.  
  471. Public Property Let CellBackColor(lThisCol As Long, lThisRow As Long, lNewValue As Long)
  472.     Dim x As Long, y As Long, lMyColWidth As Long, lMyRowHeight As Long
  473.     
  474.     If bBlockMode Then
  475.         Cells.BackColor(lThisCol, lThisRow) = lNewValue
  476.         GetCellCoordinates lThisRow, lThisCol, x&, y&
  477.         lMyColWidth = lColWidth(lThisCol)
  478.         lMyRowHeight = lRowHeight(lThisRow)
  479.         DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  480.     Else
  481.         HilightCell
  482.         HilightSelection
  483.         HilightSelection lRow1, lCol1, lRow1, lCol1
  484.         For lThisRow& = lRow1 To lRow2
  485.             For lThisCol& = lCol1 To lCol2
  486.                 Cells.BackColor(lThisCol, lThisRow) = lNewValue
  487.                 GetCellCoordinates lThisRow, lThisCol, x&, y&
  488.                 lMyColWidth = lColWidth(lThisCol)
  489.                 lMyRowHeight = lRowHeight(lThisRow)
  490.                 DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  491.             Next
  492.         Next
  493.         HilightSelection
  494.         HilightSelection lRow1, lCol1, lRow1, lCol1
  495.         HilightCell
  496.     End If
  497. End Property
  498.  
  499. Public Property Get CellForeColor(lThisCol As Long, lThisRow As Long) As Long
  500. Attribute CellForeColor.VB_MemberFlags = "440"
  501.     CellForeColor = Cells.ForeColor(lThisCol, lThisRow)
  502. End Property
  503.  
  504. Public Property Let CellForeColor(lThisCol As Long, lThisRow As Long, lNewValue As Long)
  505.     Dim x As Long, y As Long, lMyColWidth As Long, lMyRowHeight As Long
  506.     
  507.     If bBlockMode Then
  508.         Cells.ForeColor(lThisCol, lThisRow) = lNewValue
  509.         GetCellCoordinates lThisRow, lThisCol, x&, y&
  510.         lMyColWidth = lColWidth(lThisCol)
  511.         lMyRowHeight = lRowHeight(lThisRow)
  512.         DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  513.     Else
  514.         HilightCell
  515.         HilightSelection
  516.         HilightSelection lRow1, lCol1, lRow1, lCol1
  517.         For lThisRow& = lRow1 To lRow2
  518.             For lThisCol& = lCol1 To lCol2
  519.                 Cells.ForeColor(lThisCol, lThisRow) = lNewValue
  520.                 GetCellCoordinates lThisRow, lThisCol, x&, y&
  521.                 lMyColWidth = lColWidth(lThisCol)
  522.                 lMyRowHeight = lRowHeight(lThisRow)
  523.                 DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  524.             Next
  525.         Next
  526.         HilightSelection
  527.         HilightSelection lRow1, lCol1, lRow1, lCol1
  528.         HilightCell
  529.     End If
  530. End Property
  531.  
  532. Public Property Get TopRow() As Long
  533. Attribute TopRow.VB_Description = "Returns or sets the uppermost visible row (other than a fixed row) in the grid. "
  534. Attribute TopRow.VB_MemberFlags = "400"
  535.     TopRow = lTopRow
  536. End Property
  537.  
  538. Public Property Let TopRow(lNewValue As Long)
  539.     lTopRow = lNewValue
  540. End Property
  541.  
  542. Public Property Get LeftCol() As Long
  543. Attribute LeftCol.VB_Description = "Returns or sets the left-most visible column (other than a fixed column) in the grid control"
  544. Attribute LeftCol.VB_MemberFlags = "400"
  545.     LeftCol = lLeftCol
  546. End Property
  547.  
  548. Public Property Let LeftCol(lNewValue As Long)
  549.     lLeftCol = lNewValue
  550.     If bRedraw Then
  551.         RedrawAllCells True
  552.     End If
  553. End Property
  554.  
  555. Private Sub DrawCell(lThisRow As Long, lThisCol As Long, x As Long, y As Long, lWidth As Long, lHeight As Long, Optional Selected)
  556.     Dim XOffset As Byte, YOffset As Byte
  557.     Dim lpRect As RECT, iFlags As Integer
  558.     Dim cx As Long
  559.     
  560.     If IsMissing(Selected) Then Selected = False
  561.     
  562.     'Draw the cell box
  563.     If Cells.Style(lThisCol, lThisRow) = STYLE_BUTTON Then
  564.         If (lThisCol = 0 Or lThisRow = 0) And iFixedStyle = 0 Then
  565.           DrawBox x, y, lWidth, lHeight, lBackColorFixed
  566.         Else
  567.           DrawButton x, y, lWidth + 1, lHeight + 1, Cells.Value(lThisCol, lThisRow)
  568.         End If
  569.         XOffset = 2
  570.         YOffset = 0
  571.     Else
  572.         XOffset = 2
  573.         'lCellforecolor& = Cells.BackColor(lThisCol, lThisRow)
  574.         lcellbackcolor& = Cells.BackColor(lThisCol, lThisRow)
  575.         If lcellbackcolor& < 0 Then lcellbackcolor& = lBackColor
  576.         DrawBox x, y, lWidth, lHeight, lcellbackcolor&
  577.     End If
  578.     
  579.     'Print the cell text in the cell
  580.     If bDAO Then
  581.         If lThisRow > 0 And lThisCol > 0 Then
  582.             m_Recordset.AbsolutePosition = lThisRow - 1
  583.             sCellText$ = m_Recordset(lThisCol - 1) & ""
  584.         Else
  585.             sCellText$ = Cells.Text(lThisCol, lThisRow)
  586.         End If
  587.     ElseIf bRDO Then
  588.         sCellText$ = Cells.Text(lThisCol, lThisRow)
  589.     Else
  590.         sCellText$ = Cells.Text(lThisCol, lThisRow)
  591.     End If
  592.     
  593.     If lThisCol <> 0 And lThisRow <> 0 And lColMask(lThisCol) = 4 Then      'draw checkmark if checkbox mask
  594.       cx = x + (lWidth / 2) - 5
  595.       If Cells.Text(lThisCol, lThisRow) = "1" Then
  596.         DrawRect cx, y + 2, cx + 10, y + lHeight - 2, vbBlack
  597.         lpRect.Left = cx
  598.         lpRect.Top = y + 2
  599.         lpRect.Bottom = y + lHeight - 2
  600.         lpRect.Right = cx + 10
  601.         DrawLine lpRect, vbBlack
  602.         lpRect.Right = cx + 10
  603.         lpRect.Bottom = y + 2
  604.         lpRect.Top = y + lHeight - 2
  605.         lpRect.Left = cx
  606.         DrawLine lpRect, vbBlack
  607.       Else
  608.         DrawBox x + 2, y + 2, lWidth - 2, lHeight - 2, lcellbackcolor&
  609.         DrawRect cx, y + 2, cx + 10, y + lHeight - 2, vbBlack
  610.       End If
  611.     End If
  612.     
  613.     If (Len(sCellText$) And lColMask(lThisCol) <> 4) Or (lThisCol = 0 Or lThisRow = 0) Then
  614.         If lThisCol = 0 Or lThisRow = 0 Then
  615.            picGrid.ForeColor = lForeColorFixed
  616.            Set picGrid.Font = fFontFixed
  617.         Else
  618.            If Cells.ForeColor(lThisCol, lThisRow) < 0 Then
  619.              picGrid.ForeColor = lForeColor
  620.            Else
  621.              picGrid.ForeColor = Cells.ForeColor(lThisCol, lThisRow)
  622.            End If
  623.            Set picGrid.Font = fFont
  624.         End If
  625.         
  626. '        picGrid.FontName = Cells.FontName(lThisCol, lThisRow)
  627. '        picGrid.FontSize = Cells.FontSize(lThisCol, lThisRow)
  628. '        picGrid.FontBold = Cells.FontBold(lThisCol, lThisRow)
  629. '        picGrid.FontItalic = Cells.FontItalic(lThisCol, lThisRow)
  630. '        picGrid.FontUnderline = Cells.FontUnderline(lThisCol, lThisRow)
  631. '        picGrid.FontStrikethru = Cells.FontStrikethru(lThisCol, lThisRow)
  632.         
  633.         iFlags = DT_SINGLELINE
  634.         
  635.         'Select Case Cells.TextAlign(lThisCol, lThisRow)
  636.         Select Case lColAlign(lThisCol)             'kdq091498
  637.         Case ALIGN_LEFT
  638.             iFlags = iFlags + DT_LEFT
  639.         Case ALIGN_CENTER
  640.             iFlags = iFlags + DT_CENTER
  641.         Case ALIGN_RIGHT
  642.             iFlags = iFlags + DT_RIGHT
  643.         End Select
  644.         
  645.         Select Case Cells.TextAlignVertical(lThisCol, lThisRow)
  646.         Case ALIGNV_TOP
  647.             iFlags = iFlags + DT_TOP
  648.         Case ALIGNV_CENTER
  649.             iFlags = iFlags + DT_VCENTER
  650.         Case ALIGNV_BOTTOM
  651.             iFlags = iFlags + DT_BOTTOM
  652.         End Select
  653.         
  654.         lpRect.Top = y + YOffset
  655.         lpRect.Left = x + XOffset
  656.         lpRect.Right = lpRect.Left + lWidth - (XOffset * 2)
  657.         lpRect.Bottom = lpRect.Top + lHeight - (YOffset * 2)
  658.         DrawText picGrid.hDC, sCellText$, Len(sCellText$), lpRect, iFlags
  659.     End If
  660. End Sub
  661.  
  662. Public Property Get ShowGrid() As Boolean
  663. Attribute ShowGrid.VB_Description = "Determines if grid lines are to be drawn"
  664.     ShowGrid = bShowGrid
  665. End Property
  666.  
  667. Public Property Let ShowGrid(bNewValue As Boolean)
  668.     bShowGrid = bNewValue
  669.     Refresh
  670. End Property
  671.  
  672. Public Property Get GridSolid() As Boolean
  673. Attribute GridSolid.VB_Description = "Determines if the grid is solid or dashed"
  674.    GridSolid = bGridSolid
  675. End Property
  676.  
  677. Public Property Let GridSolid(bNewValue As Boolean)
  678.     bGridSolid = bNewValue
  679.     Refresh
  680. End Property
  681.  
  682. Public Sub HChange()
  683. Attribute HChange.VB_MemberFlags = "40"
  684.     Dim iDirection As Integer, lNewLeftCol As Long
  685.     Dim lOldLeftCol As Long
  686.     Dim lpRect As RECT, lpOldRect As RECT
  687.     Dim lMyColWidth As Long
  688.     Dim lMyRowHeight As Long
  689.     Dim x As Long, y As Long
  690.     
  691.     If bEditMode Then
  692.         Cells.Text(lCol, lRow) = txtEdit.Text
  693.         bEditMode = False
  694.         GetCellCoordinates lRow, lCol, x&, y&
  695.         lMyColWidth = lColWidth(lCol)
  696.         lMyRowHeight = lRowHeight(lRow)
  697.         txtEdit.Visible = False
  698.         txtEdit.ZOrder 1
  699.         DrawCell lRow, lCol, x&, y&, lMyColWidth, lMyRowHeight
  700.         DrawGridBorder
  701.         HilightCell lRow, lCol
  702.         ''raiseevent leavecell
  703.     End If
  704.     
  705.     lNewLeftCol& = scrHorizontal.Value
  706.     iDirection% = lLeftCol& - lNewLeftCol&
  707.     If Abs(iDirection%) = 1 Then
  708.         'picGrid.AutoRedraw = True
  709.         bOldRedraw = bRedraw
  710.         bRedraw = False
  711.         
  712.         'Un-hilight the old selection
  713.         HilightSelection
  714.         'Un-hilight the previous selected cell
  715.         HilightSelection lRow1, lCol1, lRow1, lCol1
  716.         'Un-hilight the border of the previous selected cell
  717.         'HilightCell
  718.         
  719.         lOldLeftCol = lLeftCol
  720.         lLeftCol = lNewLeftCol&
  721.         
  722.         'Scroll the DC
  723.         lpRect.Top = 1
  724.         If bRowHeader Then
  725.             lpRect.Left = lColWidth(0) + 2
  726.         Else
  727.             lpRect.Left = 1
  728.         End If
  729.         lpRect.Right = picGrid.ScaleWidth - 1
  730.         If iDirection > 0 Then
  731.             lMyColWidth& = lColWidth(lLeftCol&) + 1
  732.         Else
  733.             lMyColWidth& = lColWidth(lOldLeftCol&) + 1
  734.         End If
  735.         lpRect.Bottom = picGrid.ScaleHeight - 1
  736.         lRet = ScrollDC(picGrid.hDC, lMyColWidth& * iDirection, 0, lpRect, lpRect, hRegion, lpOldRect)
  737.         
  738.         If iDirection > 0 Then
  739.             DrawCol lNewLeftCol&, lpRect.Left, True
  740.         Else
  741.             DrawRightCols lLeftCol&, lMyColWidth&
  742.         End If
  743.         
  744.         'DrawGrid               'kdq090498      replace because background was not being redrawn correctly
  745.         RedrawAllCells True
  746.         
  747.         'Hilight the new selection
  748.         HilightSelection
  749.         'Un-hilight the beginning of the selection
  750.         HilightSelection lRow1, lCol1, lRow1, lCol1
  751.         'Hilight the selection cell
  752.         'HilightCell
  753.         
  754.         bRedraw = bOldRedraw
  755.         If bRedraw Then picGrid.Refresh
  756.         'picGrid.AutoRedraw = False
  757.     Else
  758.         lLeftCol = lNewLeftCol&
  759.         RedrawAllCells True
  760.     End If
  761.     
  762.     SetSizers
  763. End Sub
  764.  
  765. Public Sub VChange()
  766. Attribute VChange.VB_MemberFlags = "40"
  767.     Dim iDirection As Integer
  768.     Dim lpRect As RECT, lpOldRect As RECT
  769.     Dim hRegion As Long
  770.     Dim lMyColWidth As Long
  771.     Dim lMyRowHeight As Long
  772.     Dim x As Long, y As Long
  773.     
  774.     If bEditMode Then
  775.         'Cells.Text(lCol, lRow) = txtEdit.Text
  776.         bEditMode = False
  777.         GetCellCoordinates lRow, lCol, x&, y&
  778.         lMyColWidth = lColWidth(lCol)
  779.         lMyRowHeight = lRowHeight(lRow)
  780.         txtEdit.Visible = False
  781.         txtEdit.ZOrder 1
  782.         DrawCell lRow, lCol, x&, y&, lMyColWidth, lMyRowHeight
  783.         DrawGridBorder
  784.         HilightCell lRow, lCol
  785.         ''raiseevent leavecell
  786.     End If
  787.     
  788.     lNewTopRow& = scrVertical.Value
  789.     iDirection = lTopRow - lNewTopRow&
  790.     If Abs(iDirection) = 1 Then
  791.         'picGrid.AutoRedraw = True
  792.         bOldRedraw = bRedraw
  793.         bRedraw = False
  794.         
  795.         'Un-hilight the old selection
  796.         HilightSelection
  797.         'Un-hilight the previous selected cell
  798.         HilightSelection lRow1, lCol1, lRow1, lCol1
  799.         'Un-hilight the border of the previous selected cell
  800.         'HilightCell
  801.         
  802.         lOldTopRow& = lTopRow
  803.         lTopRow = lNewTopRow&
  804.         
  805.         'Scroll the DC
  806.         lpRect.Left = 1
  807.         If bColHeader Then
  808.             lpRect.Top = lRowHeight(0) + 2
  809.         Else
  810.             lpRect.Top = 1
  811.         End If
  812.         lpRect.Right = picGrid.ScaleWidth - 1
  813.         If iDirection > 0 Then
  814.             lMyRowHeight& = lRowHeight(lTopRow&) + 1
  815.         Else
  816.             lMyRowHeight& = lRowHeight(lOldTopRow&) + 1
  817.         End If
  818.         'If scrHorizontal.Visible Then
  819.         '    lScrollHeight = scrHorizontal.Height
  820.         'Else
  821.             lScrollHeight = 0
  822.         'End If
  823.         
  824.         lpRect.Bottom = picGrid.ScaleHeight - lScrollHeight - 1
  825.         lRet = ScrollDC(picGrid.hDC, 0, lMyRowHeight& * iDirection, lpRect, lpRect, hRegion, lpOldRect)
  826.         
  827.         If iDirection > 0 Then
  828.             DrawRow lTopRow&, lpRect.Top, True
  829.         Else
  830.             DrawBottomRows lTopRow&, lMyRowHeight&
  831.         End If
  832.         
  833.         'DrawGrid                   kdq090498   replaced because background was not redrawing correctly
  834.         RedrawAllCells False
  835.  
  836.         'Hilight the new selection
  837.         HilightSelection
  838.         'Un-hilight the beginning of the selection
  839.         HilightSelection lRow1, lCol1, lRow1, lCol1
  840.         'Hilight the selection cell
  841.         'HilightCell
  842.        
  843.         bRedraw = bOldRedraw
  844.         If bRedraw Then picGrid.Refresh
  845.         'picGrid.AutoRedraw = False
  846.     Else
  847.         lTopRow = lNewTopRow&
  848.         RedrawAllCells False
  849.     End If
  850.     
  851.     SetSizers
  852. End Sub
  853.  
  854. Public Sub DrawRow(lThisRow As Long, y As Long, bDrawHeader As Boolean)
  855. Attribute DrawRow.VB_MemberFlags = "40"
  856.     Dim lThisCol As Long, x As Long, lMyColWidth As Long, lMyRowHeight As Long
  857.     Dim lScaleWidth As Long
  858.     
  859.     If bShowGrid Then
  860.         bytGridLine = 1
  861.     Else
  862.         bytGridLine = 0
  863.     End If
  864.     
  865.     lMyRowHeight = lRowHeight(lThisRow)
  866.     If bRowHeader Then
  867.         x& = 1
  868.         lMyColWidth = lColWidth(0)
  869.         'If bDrawHeader Then
  870.             DrawCell lThisRow, 0, x&, y&, lMyColWidth, lMyRowHeight
  871.         'End If
  872.         x& = x& + lMyColWidth + bytGridLine
  873.     Else
  874.         x& = 1
  875.     End If
  876.     lScaleWidth = picGrid.ScaleWidth
  877.     
  878.     If lLeftCol > 1 Then
  879.         bWidthOverflow = True
  880.     Else
  881.         bWidthOverflow = False          'kdq090198          added to make sure scrollbars turn on/off
  882.     End If
  883.     
  884.     For lThisCol = lLeftCol To lCols
  885.         lMyColWidth = lColWidth(lThisCol)
  886.         DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  887.         x& = x& + lMyColWidth + bytGridLine
  888.         If x& > lScaleWidth - 1 Then
  889.             bWidthOverflow = True
  890.             If lLargeHChange = 0 Then
  891.                 lLargeHChange = lThisCol - lLeftCol             '- 1
  892.                 scrHorizontal.LargeChange = lLargeHChange
  893.             End If
  894.             Exit For
  895.         End If
  896.     Next
  897.     lGridWidth = x& - 1
  898.     If lGridWidth > lScaleWidth - 1 Then lGridWidth = lScaleWidth - 1
  899. End Sub
  900.  
  901. Public Sub DrawCol(lThisCol As Long, x As Long, bDrawHeader)
  902. Attribute DrawCol.VB_MemberFlags = "40"
  903.     Dim lThisRow As Long, y As Long, lMyColWidth As Long, lMyRowHeight As Long
  904.     Dim lScaleHeight As Long
  905.     
  906.     If bShowGrid Then
  907.         bytGridLine = 1
  908.     Else
  909.         bytGridLine = 0
  910.     End If
  911.     
  912.     lMyColWidth = lColWidth(lThisCol)
  913.     If bColHeader Then
  914.         y& = 1
  915.         lMyRowHeight = lRowHeight(0)
  916.         If bDrawHeader Then
  917.             DrawCell 0, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  918.         End If
  919.         y& = y& + lMyRowHeight + bytGridLine
  920.     Else
  921.         y& = 1
  922.     End If
  923.     lScaleHeight& = picGrid.ScaleHeight
  924.     
  925.     If lTopRow > 1 Then
  926.         bHeightOverflow = True
  927.     Else
  928.         bHeightOverflow = False          'kdq090198          added to make sure scrollbars turn on/off
  929.     End If
  930.     For lThisRow = lTopRow To lRows
  931.         lMyRowHeight = lRowHeight(lThisRow)
  932.         DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight
  933.         y& = y& + lMyRowHeight + bytGridLine
  934.         If y& > lScaleHeight Then
  935.             bHeightOverflow = True
  936.             'scrVertical.LargeChange = lThisRow - lTopRow - 2
  937.             Exit For
  938.         End If
  939.     Next
  940.     lGridHeight = y& - 1
  941.     If lGridHeight > lScaleHeight - 1 Then lGridHeight = lScaleHeight - 1
  942. End Sub
  943.  
  944. Private Sub DrawBottomRows(lThisTopRow As Long, lUpdateHeight As Long)
  945.     Dim lScaleHeight As Long, lScaleWidth As Long
  946.     
  947.     lScaleHeight = picGrid.ScaleHeight
  948.     lScaleWidth = picGrid.ScaleWidth
  949.     
  950.     If bShowGrid Then
  951.         bytGridLine = 1
  952.     Else
  953.         bytGridLine = 0
  954.     End If
  955.     
  956.     'If scrHorizontal.Visible Then
  957.     '    lScrollHeight = scrHorizontal.Height
  958.     'Else
  959.         lScrollHeight = 0
  960.     'End If
  961.     
  962.     If bColHeader Then
  963.         y& = lRowHeight(0) + 1 + bytGridLine
  964.     Else
  965.         y& = 1
  966.     End If
  967.     For l& = lThisTopRow To lRows
  968.         lMyRowHeight = lRowHeight(l&)
  969.         If y& < lScaleHeight - lScrollHeight - lUpdateHeight - lMyRowHeight - 2 Then
  970.             y& = y& + lMyRowHeight + bytGridLine
  971.         Else
  972.             For lRemainder& = l& To lRows
  973.                 DrawRow lRemainder&, y&, True
  974.                 y& = y& + lRowHeight(lRemainder&) + bytGridLine
  975.                 If l& = lRows& Or y& > lScaleHeight Then
  976.                     Exit For
  977.                 End If
  978.             Next
  979.             Exit For
  980.         End If
  981.     Next
  982.     lGridHeight& = y& - 1
  983.     DrawBox 1, lGridHeight + 1, lScaleWidth, lScaleHeight - lGridHeight, COLOR_GREY
  984. End Sub
  985.  
  986. 'kdq090398 added this sub to draw grid border in black
  987. Private Sub DrawGridBorder(Optional StartRow, Optional StartCol, Optional EndRow, Optional EndCol)
  988.     Dim lpRect As RECT
  989.         
  990.     If IsMissing(StartRow) Then StartRow = lTopRow
  991.     If IsMissing(StartCol) Then StartCol = lLeftCol
  992.     If IsMissing(EndRow) Then EndRow = lRows
  993.     If IsMissing(EndCol) Then EndCol = lCols
  994.     If IsMissing(Inverted) Then Inverted = False
  995.         
  996.         GetCellCoordinates StartRow, StartCol, x1&, y1&
  997.         GetCellCoordinates EndRow, EndCol, x2&, Y2&
  998.  
  999.         If iFixedStyle = 0 Then
  1000.             'draw top black line
  1001.             lpRect.Left = x1&
  1002.             lpRect.Top = y1&
  1003.             lpRect.Right = x2& + lColWidth(EndCol)
  1004.             lpRect.Bottom = y1&
  1005.             DrawLine lpRect, vbBlack
  1006.         End If
  1007.  
  1008.         'draw bottom black line
  1009.         lpRect.Left = x1&
  1010.         lpRect.Top = Y2& + lRowHeight(EndRow)
  1011.         lpRect.Right = x2& + lColWidth(EndCol)
  1012.         lpRect.Bottom = Y2& + lRowHeight(EndRow)
  1013.         DrawLine lpRect, vbBlack
  1014.  
  1015.         'draw left side black line
  1016.         If bRowHeader = False Then
  1017.             lpRect.Left = x1&
  1018.             lpRect.Top = y1&
  1019.             lpRect.Right = x1&
  1020.             lpRect.Bottom = Y2& + lRowHeight(EndRow)
  1021.             DrawLine lpRect, vbBlack
  1022.         End If
  1023.  
  1024.         'draw right side black line
  1025.         lpRect.Left = x2& + lColWidth(EndCol)
  1026.         lpRect.Top = y1&
  1027.         lpRect.Right = x2& + lColWidth(EndCol)
  1028.         lpRect.Bottom = Y2& + lRowHeight(EndRow)
  1029.         DrawLine lpRect, vbBlack
  1030.  
  1031.         If iFixedStyle = 0 Then
  1032.             DrawRect x1&, y1& - lRowHeight(StartRow) - 1, x2& + lColWidth(EndCol), y1&, vbBlack
  1033.         End If
  1034. End Sub
  1035.  
  1036. Private Sub DrawGrid(Optional StartRow, Optional StartCol, Optional EndRow, Optional EndCol, Optional Inverted)
  1037.     Dim lScaleWidth As Long, lScaleHeight As Long
  1038.     Dim lpRect As RECT
  1039.     
  1040.     If IsMissing(StartRow) Then StartRow = lTopRow
  1041.     If IsMissing(StartCol) Then StartCol = lLeftCol
  1042.     If IsMissing(EndRow) Then EndRow = lRows
  1043.     If IsMissing(EndCol) Then EndCol = lCols
  1044.     If IsMissing(Inverted) Then Inverted = False
  1045.     
  1046.     lScaleHeight = picGrid.ScaleHeight
  1047.     lScaleWidth = picGrid.ScaleWidth
  1048.     
  1049.     If bShowGrid Then
  1050.         If bGridSolid = False Then picGrid.DrawStyle = 2    'dotted
  1051.         
  1052.         GetCellCoordinates StartRow, StartCol, x1&, y1&
  1053.         x1& = x1&
  1054.         y1& = y1&
  1055.         GetCellCoordinates EndRow, EndCol, x2&, Y2&
  1056.         x2& = x2&
  1057.         Y2& = Y2&
  1058.         
  1059.         lpRect.Top = y1&
  1060.         lpRect.Bottom = Y2& + lRowHeight(EndRow)
  1061.         'X& = X1& + lColWidth(StartCol)
  1062.         If bRowHeader Then
  1063.             x& = lColWidth(0) + bytGridLine
  1064.         Else
  1065.             x& = 0
  1066.         End If
  1067.         For lThisCol = StartCol To EndCol
  1068.             x& = x& + lColWidth(lThisCol) + bytGridLine
  1069.             If x& > lScaleWidth Then Exit For
  1070.             lpRect.Left = x&
  1071.             lpRect.Right = x&
  1072.             DrawLine lpRect, lGridLineColor
  1073.         Next
  1074.         
  1075.         If bColHeader Then
  1076.             y& = lRowHeight(0) + bytGridLine
  1077.         Else
  1078.             y& = 0
  1079.         End If
  1080.         lpRect.Left = x1&
  1081.         lpRect.Right = x2& + lColWidth(EndCol)
  1082.         'Y& = Y1& + lRowHeight(StartRow)
  1083.         For lThisRow = StartRow To EndRow
  1084.             y& = y& + lRowHeight(lThisRow) + bytGridLine
  1085.             If y& > lScaleHeight Then Exit For
  1086.             lpRect.Top = y&
  1087.             lpRect.Bottom = y&
  1088.             DrawLine lpRect, lGridLineColor
  1089.         Next
  1090.         picGrid.DrawStyle = 0    'Solid
  1091.     
  1092.     End If
  1093.     
  1094.     'Draw the right, bottom and the grey box at the bottom right
  1095.     'DrawBottomRight
  1096.     DrawGridBorder StartRow, StartCol, EndRow, EndCol
  1097.     'Draw the blank grey box at the end of the scroll bars
  1098.     If (bWidthOverflow And bHeightOverflow) Or (scrHorizontal.Visible And scrVertical.Visible) Then DrawBox lScaleWidth - 20, lScaleHeight - 20, 20, 20, COLOR_GREY
  1099. End Sub
  1100.  
  1101. 'Public Sub SetRowHeight(lThisRow&, lNewHeight&)
  1102. '    lRowHeight(lThisRow&) = lNewHeight&
  1103. '    RedrawAllCells True
  1104. 'End Sub
  1105.  
  1106. Public Property Get Row() As Long
  1107. Attribute Row.VB_Description = "Sets/gets the current row"
  1108. Attribute Row.VB_MemberFlags = "400"
  1109.     Row = lRow
  1110. End Property
  1111.  
  1112. Public Property Let Row(lNewValue As Long)
  1113.     HilightCell lRow, lCol
  1114.     lRow = lNewValue
  1115.     HilightCell
  1116. End Property
  1117.  
  1118. Public Property Get Col() As Long
  1119. Attribute Col.VB_Description = "Gets/sets the current column number"
  1120. Attribute Col.VB_MemberFlags = "400"
  1121.     Col = lCol
  1122. End Property
  1123.  
  1124. Public Property Let Col(lNewValue As Long)
  1125.     HilightCell lRow, lCol
  1126.     lCol = lNewValue
  1127.     HilightCell
  1128. End Property
  1129.  
  1130. Public Property Get Text() As String
  1131. Attribute Text.VB_Description = "Gets/sets the text for the current row and column"
  1132. Attribute Text.VB_MemberFlags = "400"
  1133.     Text = Cells.Text(lCol, lRow)
  1134. End Property
  1135.  
  1136. Public Property Let Text(sNewValue As String)
  1137.     Cells.Text(lCol, lRow) = sNewValue
  1138. End Property
  1139.  
  1140. Public Property Get TextMatrix(vRow As Long, vCol As Long) As String
  1141. Attribute TextMatrix.VB_Description = "Gets/sets the text for the specified row and column"
  1142.     TextMatrix = Cells.Text(vCol, vRow)
  1143. End Property
  1144.  
  1145. Public Property Let TextMatrix(vRow As Long, vCol As Long, sNewValue As String)
  1146.     Cells.Text(vCol, vRow) = sNewValue
  1147. End Property
  1148.  
  1149. Public Property Get Redraw() As Boolean
  1150.     Redraw = bRedraw
  1151. End Property
  1152.  
  1153. Public Property Let Redraw(bNewValue As Boolean)
  1154.     bRedraw = bNewValue
  1155.     Refresh
  1156. End Property
  1157.  
  1158. Private Sub DrawRightCols(lThisLeftCol As Long, lUpdateWidth As Long)
  1159.     Dim lScaleWidth As Long, lScaleHeight As Long
  1160.     Dim lMyColWidth As Long
  1161.     
  1162.     lScaleWidth = picGrid.ScaleWidth
  1163.     lScaleHeight = picGrid.ScaleHeight
  1164.     
  1165.     If bShowGrid Then
  1166.         bytGridLine = 1
  1167.     Else
  1168.         bytGridLine = 0
  1169.     End If
  1170.     
  1171.     'If scrVertical.Visible Then
  1172.     '    lScrollWidth = scrVertical.Width
  1173.     'Else
  1174.         lScrollWidth = 0
  1175.     'End If
  1176.     
  1177.     If bRowHeader Then
  1178.         x& = lColWidth(0) + 1 + bytGridLine
  1179.     Else
  1180.         x& = 1
  1181.     End If
  1182.     For l& = lThisLeftCol To lCols
  1183.         lMyColWidth = lColWidth(l&)
  1184.         If x& < lScaleWidth - lUpdateWidth - lMyColWidth - lScrollWidth Then
  1185.             x& = x& + lMyColWidth + bytGridLine
  1186.         Else
  1187.             For lRemainder& = l& To lCols
  1188.                 DrawCol lRemainder&, x&, True
  1189.                 x& = x& + lColWidth(lRemainder&) + bytGridLine
  1190.                 If l& = lCols& Or x& > lScaleWidth Then
  1191.                     Exit For
  1192.                 End If
  1193.             Next
  1194.             Exit For
  1195.         End If
  1196.     Next
  1197.     lGridWidth& = x& - 1
  1198.     DrawBox lGridWidth + 1, 1, lScaleWidth - 1, lScaleHeight - 1, COLOR_GREY
  1199. End Sub
  1200.  
  1201. Private Sub RedrawAllCells(bDrawColHeader As Boolean)
  1202.     Dim lMyRowHeight As Long
  1203.     Dim lScaleHeight As Long, lScaleWidth As Long
  1204.     Dim lpRect As RECT
  1205.     
  1206.     'picGrid.AutoRedraw = True
  1207.     
  1208.     If bColHeader Then
  1209.         If bDrawColHeader Then
  1210.             DrawRow 0, 1, True
  1211.         End If
  1212.         y& = 1 + lRowHeight(0) + bytGridLine
  1213.         lGridHeight = 1 + lRowHeight(0)
  1214.     Else
  1215.         lGridHeight = 0
  1216.         y& = 1
  1217.     End If
  1218.     lScaleHeight = picGrid.ScaleHeight
  1219.     lScaleWidth = picGrid.ScaleWidth
  1220.     For lThisRow& = lTopRow To lRows
  1221.         lMyRowHeight& = lRowHeight(lThisRow&)
  1222.         DrawRow lThisRow&, y&, True
  1223.         y& = y& + lRowHeight(lThisRow&) + bytGridLine
  1224.         If lThisRow& = lRows Or y& > lScaleHeight - 1 Then
  1225.             If lLargeVChange = 0 Then
  1226.                 lLargeVChange = lThisRow& - lTopRow - 1
  1227.                 If lLargeVChange > 0 Then scrVertical.LargeChange = lLargeVChange
  1228.             End If
  1229.             lGridHeight = y& - 1
  1230.             Exit For
  1231.         End If
  1232.     Next
  1233.     
  1234.     If lGridHeight >= lScaleHeight - 1 Then
  1235.         bHeightOverflow = True
  1236.         lGridHeight = lScaleHeight - 1
  1237.         scrVertical.Tag = True
  1238.     Else
  1239.         If lTopRow > 1 Then
  1240.             bHeightOverflow = True
  1241.             scrVertical.Tag = True
  1242.         Else
  1243.             bHeightOverflow = False          'kdq090198          added to make sure scrollbars turn on/off
  1244.             scrVertical.Tag = False
  1245.         End If
  1246.     End If
  1247.     
  1248.     If lGridWidth >= lScaleWidth - 1 Then
  1249.         bWidthOverflow = True
  1250.         lGridWidth = lScaleWidth - 1
  1251.         scrHorizontal.Tag = True
  1252.     Else
  1253.         If lLeftCol > 1 Then
  1254.             bWidthOverflow = True
  1255.             scrHorizontal.Tag = True
  1256.         Else
  1257.             bWidthOverflow = False          'kdq090198          added to make sure scrollbars turn on/off
  1258.             scrHorizontal.Tag = False
  1259.         End If
  1260.     End If
  1261.     
  1262.     
  1263.     'color in space between grid and horizontal scrollbar
  1264.     DrawBox 1, lGridHeight + 1, lScaleWidth - 1, lScaleHeight - 1, lBackColorBkg        'COLOR_GREY
  1265.     'color in space between grid and vertical scrollbar
  1266.     DrawBox lGridWidth + 1, 1, lScaleWidth - GridWidth, lScaleHeight - 1, lBackColorBkg         'COLOR_GREY
  1267.     
  1268.     If Rows > 0 Then
  1269.     DrawGrid
  1270.     
  1271.         HilightSelection
  1272.         HilightSelection lRow1, lCol1, lRow1, lCol1
  1273.  
  1274.         bOver = GetCellCoordinates(lRow, lCol, x&, y&)
  1275.         If bOver = False Then
  1276.             HilightCell
  1277.         End If
  1278.     End If
  1279.     SetSizers
  1280.     ''Draw the grid border
  1281.     'lpRect.Left = 0
  1282.     'lpRect.Top = 0
  1283.     'lpRect.Bottom = UserControl.ScaleHeight
  1284.     'lpRect.Right = 0
  1285.     'DrawLine lpRect, vbBlack, UserControl.hDC
  1286.     '
  1287.     'lpRect.Right = UserControl.ScaleWidth - 1
  1288.     'lpRect.Bottom = 0
  1289.     'DrawLine lpRect, vbBlack, UserControl.hDC
  1290.     '
  1291.     'lpRect.Left = lpRect.Right
  1292.     'lpRect.Bottom = UserControl.ScaleHeight
  1293.     'DrawLine lpRect, vbBlack, UserControl.hDC
  1294.     
  1295.     'If bRedraw Then picGrid.Refresh
  1296.     'picGrid.AutoRedraw = False
  1297. End Sub
  1298.  
  1299. Private Sub DrawBox(x As Long, y As Long, lWidth As Long, lHeight As Long, lColor As Long)
  1300.     Dim lpRect As RECT, hBrush As Long
  1301.     
  1302.     lpRect.Top = y
  1303.     lpRect.Left = x
  1304.     lpRect.Right = lpRect.Left + lWidth
  1305.     lpRect.Bottom = lpRect.Top + lHeight
  1306.     hBrush = CreateSolidBrush(lColor)
  1307.     FillRect picGrid.hDC, lpRect, hBrush
  1308.     DeleteObject hBrush
  1309. End Sub
  1310.  
  1311. Private Sub DrawRect(x As Long, y As Long, x1 As Long, y1 As Long, lColor As Long)
  1312.     Dim lpRect As RECT
  1313.     picGrid.ForeColor = lColor
  1314.     
  1315.     'draw top line
  1316.     lpRect.Left = x
  1317.     lpRect.Top = y
  1318.     lpRect.Right = x1
  1319.     lpRect.Bottom = y
  1320.     MoveToEx picGrid.hDC, lpRect.Left, lpRect.Top, 0
  1321.     LineTo picGrid.hDC, lpRect.Right, lpRect.Bottom
  1322.     
  1323.     'draw bottom line
  1324.     lpRect.Left = x
  1325.     lpRect.Top = y1
  1326.     lpRect.Right = x1
  1327.     lpRect.Bottom = y1
  1328.     MoveToEx picGrid.hDC, lpRect.Left, lpRect.Top, 0
  1329.     LineTo picGrid.hDC, lpRect.Right, lpRect.Bottom
  1330.     
  1331.     'draw left line
  1332.     lpRect.Left = x
  1333.     lpRect.Top = y
  1334.     lpRect.Right = x
  1335.     lpRect.Bottom = y1
  1336.     MoveToEx picGrid.hDC, lpRect.Left, lpRect.Top, 0
  1337.     LineTo picGrid.hDC, lpRect.Right, lpRect.Bottom
  1338.     
  1339.     'draw right line
  1340.     lpRect.Left = x1
  1341.     lpRect.Top = y
  1342.     lpRect.Right = x1
  1343.     lpRect.Bottom = y1
  1344.     MoveToEx picGrid.hDC, lpRect.Left, lpRect.Top, 0
  1345.     LineTo picGrid.hDC, lpRect.Right, lpRect.Bottom
  1346.     
  1347. End Sub
  1348.  
  1349. Private Sub DrawLine(lpRect As RECT, lColor As Long, Optional DC)
  1350.     If IsMissing(DC) Then DC = picGrid.hDC
  1351.     picGrid.ForeColor = lColor
  1352.     MoveToEx DC, lpRect.Left, lpRect.Top, 0
  1353.     LineTo DC, lpRect.Right, lpRect.Bottom
  1354. End Sub
  1355.  
  1356. Public Property Get GridLineColor() As OLE_COLOR
  1357. Attribute GridLineColor.VB_Description = "Gets/sets the color used to draw the grid lines"
  1358.     GridLineColor = lGridLineColor
  1359. End Property
  1360.  
  1361. Public Property Let GridLineColor(lNewValue As OLE_COLOR)
  1362.     lGridLineColor = lNewValue
  1363.     Refresh
  1364.     PropertyChanged "GridLineColor"
  1365. End Property
  1366.  
  1367. Private Sub HilightCell(Optional ThisRow, Optional ThisCol)
  1368.     Dim lMyColWidth As Long, lMyRowHeight As Long
  1369.     Dim lScaleWidth As Long, lScaleHeight As Long
  1370.     Dim lpRect As RECT
  1371.     Dim bOver As Boolean
  1372.     Dim bytTopWidth As Byte
  1373.     
  1374.     If lRows < 1 Or lCols < 1 Then Exit Sub     'kdq090298
  1375.     If IsMissing(ThisRow) Then ThisRow = lRow
  1376.     If IsMissing(ThisCol) Then ThisCol = lCol
  1377.     
  1378.     lScaleWidth = picGrid.ScaleWidth
  1379.     lScaleHeight = picGrid.ScaleHeight
  1380.     
  1381.     If ThisRow >= lTopRow And ThisCol >= lLeftCol Then
  1382.         bOver = GetCellCoordinates(ThisRow, ThisCol, x&, y&)
  1383.         If bOver = False Then
  1384.             'Now we have the X and Y coordinates of the cell and we know
  1385.             '   that the cell is visible on the screen
  1386.             lMyColWidth = lColWidth(ThisCol)
  1387.             lMyRowHeight = lRowHeight(ThisRow)
  1388.             
  1389.             'Draw a black box around the cell
  1390.             picGrid.DrawMode = vbInvert
  1391.             
  1392.             'kdq090498      changed to force highlight to be the same on all columns
  1393.                 lpRect.Left = x&
  1394.                 lpRect.Top = y&
  1395.                 lpRect.Right = lpRect.Left + lMyColWidth
  1396.                 lpRect.Bottom = lpRect.Top + lMyRowHeight
  1397.                 di = DrawFocusRect(picGrid.hDC, lpRect)
  1398.                 
  1399.             
  1400.             picGrid.DrawMode = vbCopyPen
  1401.             picGrid.DrawWidth = 1
  1402.             
  1403.             'Set the position of the edit box
  1404.             txtEdit.Move x& + 3, y& + 2, lMyColWidth - 3, lMyRowHeight          'kdq090198      x and y were adjusted due to movement of picGrid
  1405.             If bEditMode Then
  1406.                 txtEdit.Visible = True
  1407.             Else
  1408.                 If txtEdit.Visible Then
  1409.                 txtEdit.Visible = False
  1410.                 'raiseevent leavecell
  1411.                 RaiseEvent AfterEdit(lRow, lCol, Text)
  1412.                 End If
  1413.                 txtEdit.ZOrder 1
  1414.             End If
  1415.         End If
  1416.     End If
  1417.     
  1418.     If bRedraw Then picGrid.Refresh
  1419. End Sub
  1420.  
  1421. Public Sub MouseDown(button As Integer, Shift As Integer, x As Single, y As Single)
  1422. Attribute MouseDown.VB_MemberFlags = "40"
  1423.     Dim lX As Long, lY As Long, lMyColWidth As Long, lMyRowHeight As Long
  1424.     Dim lNewCol As Long, lNewRow As Long
  1425.     Dim iMousePointer As Integer
  1426.     
  1427.     bMouseDown = True
  1428.     
  1429.     'Find out if we're sizing columns or rows
  1430.     iMousePointer% = UserControl.MousePointer
  1431.     If iMousePointer = vbSizeWE Then
  1432.         'Initiate the column size drag
  1433.         picSizer.Width = 2
  1434.         picSizer.Height = UserControl.ScaleHeight
  1435.         picSizer.Top = 0
  1436.         picSizer.Left = x
  1437.         picSizer.Visible = True
  1438.         bSizingCol = True
  1439.     ElseIf iMousePointer = vbSizeNS Then
  1440.         'Initiate the row size drag
  1441.         picSizer.Height = 2
  1442.         picSizer.Width = UserControl.ScaleWidth
  1443.         picSizer.Left = 0
  1444.         picSizer.Top = y
  1445.         picSizer.Visible = True
  1446.         bSizingRow = True
  1447.     Else
  1448.     
  1449.     'Un-select the spreadsheet 0,0 selector
  1450.     If Cells.Value(0, 0) Then
  1451.         Cells.Value(0, 0) = False
  1452.         GetCellCoordinates 0, 0, lX, lY
  1453.         lMyColWidth = ColWidth(0)
  1454.         lMyRowHeight = RowHeight(0)
  1455.         DrawCell 0, 0, 1, 1, lMyColWidth, lMyRowHeight
  1456.     End If
  1457.     
  1458.     'Un-select any col selectors
  1459.     lMyRowHeight = RowHeight(0)
  1460.     For lOldCol& = lCol1 To lCol2
  1461.         If Cells.Value(lOldCol&, 0) Then
  1462.             Cells.Value(lOldCol&, 0) = False
  1463.             bOver = GetCellCoordinates(0, lOldCol&, lX, lY)
  1464.             If Not bOver Then
  1465.                 lMyColWidth = ColWidth(lOldCol)
  1466.                 DrawCell 0, lOldCol, lX, 1, lMyColWidth, lMyRowHeight
  1467.             End If
  1468.         End If
  1469.     Next
  1470.     
  1471.     'Un-select any row selectors
  1472.     lMyColWidth = ColWidth(0)
  1473.     For lOldRow& = lRow1 To lRow2
  1474.         If Cells.Value(0, lOldRow&) Then
  1475.             Cells.Value(0, lOldRow&) = False
  1476.             bOver = GetCellCoordinates(lOldRow&, 0, lX, lY)
  1477.             If Not bOver Then
  1478.                 lMyRowHeight = RowHeight(lOldRow&)
  1479.                 DrawCell lOldRow, 0, 1, lY, lMyColWidth, lMyRowHeight
  1480.             End If
  1481.         End If
  1482.     Next
  1483.     
  1484.     'Process the mouse down
  1485.     If scrHorizontal.Visible And scrVertical.Visible And x > scrVertical.Left And y > scrHorizontal.Top Then Exit Sub
  1486.     
  1487.     lNewRow = RowFromPoint(x, y)
  1488.     lNewCol = ColFromPoint(x, y)
  1489.     
  1490.     If (lNewRow = 0 Or lNewCol = 0) And (lNewRow > -1 And lNewCol > -1) Then
  1491.         'mouse clicked on a fixed cell
  1492.         If (Shift And 1) And (button And 1) Then
  1493.             'Extend the existing selection
  1494.         Else
  1495.             If lRow1 <> lRow2 Or lCol1 <> lCol2 Then
  1496.                 HilightSelection
  1497.                 'Un-hilight the previous selected cell
  1498.                 HilightSelection lRow1, lCol1, lRow1, lCol1
  1499.             End If
  1500.             
  1501.             HilightCell
  1502.             
  1503.             If bAllowSelection And iSelectionMode > 0 Then Cells.Value(lNewCol, lNewRow) = True
  1504.             bOver = GetCellCoordinates(lNewRow, lNewCol, lX, lY)
  1505.             lMyColWidth = ColWidth(lNewCol)
  1506.             lMyRowHeight = RowHeight(lNewRow)
  1507.             If lNewCol = 0 And lNewRow = 0 Then
  1508.                 If bAllowSelection And iSelectionMode = 0 Then
  1509.                 DrawCell lNewRow, lNewCol, 1, 1, lMyColWidth, lMyRowHeight
  1510.                 
  1511.                 lMyRowHeight = RowHeight(0)
  1512.                 For lMyCol& = 1 To lCols
  1513.                     Cells.Value(lMyCol&, 0) = True
  1514.                     
  1515.                     bOver = GetCellCoordinates(0, lMyCol, lX, lY)
  1516.                     If Not bOver Then
  1517.                         lMyColWidth = ColWidth(lMyCol)
  1518.                         DrawCell 0, lMyCol, lX, 1, lMyColWidth, lMyRowHeight
  1519.                     End If
  1520.                 Next
  1521.                 
  1522.                 lMyColWidth = ColWidth(0)
  1523.                 For lMyRow& = 1 To lRows
  1524.                     Cells.Value(0, lMyRow&) = True
  1525.                 
  1526.                     bOver = GetCellCoordinates(lMyRow, 0, lX, lY)
  1527.                     If Not bOver Then
  1528.                         lMyRowHeight = RowHeight(lMyRow)
  1529.                         DrawCell lMyRow, 0, 1, lY, lMyColWidth, lMyRowHeight
  1530.                     End If
  1531.                 Next
  1532.                 
  1533.                 lCol1 = 1
  1534.                 lCol2 = lCols
  1535.                 lRow1 = 1
  1536.                 lRow2 = lRows
  1537.                 
  1538.                 bSelectingRows = True
  1539.                 bSelectingCols = True
  1540.                 End If
  1541.             Else
  1542.                 If lNewCol = 0 Then
  1543.                     'clicked on row header
  1544.                     If iSelectionMode = 1 And bAllowSelection Then
  1545.                         DrawCell lNewRow, lNewCol, 1, lY, lMyColWidth, lMyRowHeight
  1546.                         lCol1 = 1
  1547.                         lCol2 = lCols
  1548.                         lRow1 = lNewRow
  1549.                         lRow2 = lNewRow
  1550.                         
  1551.                         bSelectingRows = True
  1552.                     End If
  1553.                 Else
  1554.                     'clicked on column header
  1555.                     If iSelectionMode = 2 And bAllowSelection Then
  1556.                         DrawCell lNewRow, lNewCol, lX, 1, lMyColWidth, lMyRowHeight
  1557.                         lCol1 = lNewCol
  1558.                         lCol2 = lNewCol
  1559.                         lRow1 = 1
  1560.                         lRow2 = lRows
  1561.                     
  1562.                         bSelectingCols = True
  1563.                     End If
  1564.                 End If
  1565.             End If
  1566.         End If
  1567.             
  1568.         'Hilight the new selection
  1569.         HilightSelection
  1570.         
  1571.         'Un-hilight the previous selected cell
  1572.         HilightSelection lRow1, lCol1, lRow1, lCol1
  1573.         
  1574.         lCol = lCol1
  1575.         lRow = lRow1
  1576.  
  1577.         HilightCell
  1578.         
  1579.         'If bRedraw Then picGrid.Refresh
  1580.     ElseIf lNewRow > -1 And lNewCol > -1 Then
  1581.             
  1582.         'mouse clicked on unfixed cell
  1583.         
  1584.         'kdq090998
  1585.         'added so if last col does not fit in grid and is clicked on, auto move grid
  1586.         bOver = GetCellCoordinates(lNewRow, lNewCol, lX, lY)
  1587.         If lX + lColWidth(lNewCol) > scrVertical.Left Then scrHorizontal.Value = scrHorizontal.Value + 1
  1588.         If lY + lRowHeight(lNewRow) > scrHorizontal.Top Then scrVertical.Value = scrVertical.Value + 1
  1589.         
  1590.         If (Shift And 1) And (button And 1) Then
  1591.             'Shift was pressed
  1592.             'Un-hilight the old selection
  1593.             HilightSelection lRow1, lCol1, lRow2, lCol2
  1594.             'Hilight the new selection
  1595.             lRow2 = lNewRow
  1596.             lCol2 = lNewCol
  1597.             HilightSelection
  1598.         Else
  1599.             If lCol2 <> lCol1 Or lRow2 <> lRow1 Then
  1600.                 HilightSelection
  1601.                 'Un-hilight the previous selected cell
  1602.                 HilightSelection lRow1, lCol1, lRow1, lCol1
  1603.             End If
  1604.             
  1605.             lRow1 = lNewRow
  1606.             lCol1 = lNewCol
  1607.             lRow2 = lRow1
  1608.             lCol2 = lCol1
  1609.             If lNewRow <> lRow Or lNewCol <> lCol Then
  1610.                 'Re-set the edit box
  1611.                 If bEditMode Then
  1612.                     HideEdit
  1613.                     'picGrid.AutoRedraw = False
  1614.                 Else
  1615.                     HilightCell lRow, lCol
  1616.                 End If
  1617.                 
  1618.                 bRedraw = False
  1619.                 If lNewRow > -1 Then lRow = lNewRow
  1620.                 If lNewCol > -1 Then lCol = lNewCol
  1621.                 If lNewRow > -1 Or lNewCol > -1 Then
  1622.                     'Fire the event
  1623.                     'FireEvent 1
  1624.                 End If
  1625.                 bRedraw = True
  1626.                 HilightCell
  1627.             End If
  1628.         End If
  1629.     End If
  1630.     End If
  1631.     'UserControl.Refresh
  1632.     If txtEdit.Visible Then
  1633.       txtEdit.Visible = False
  1634.       'raiseevent leavecell
  1635.       RaiseEvent AfterEdit(lRow, lCol, Text)
  1636.     End If
  1637.     List1.Visible = False
  1638.     cmdLookup.Visible = False
  1639.     ShowLookup
  1640. End Sub
  1641.  
  1642. Private Function RowFromPoint(x As Single, y As Single) As Long
  1643.     Dim lY As Long, lMyRowHeight As Long
  1644.     
  1645.     If bShowGrid Then
  1646.         bytGridLine = 1
  1647.     Else
  1648.         bytGridLine = 0
  1649.     End If
  1650.     
  1651.     If bColHeader Then
  1652.         lY& = lRowHeight(0) + bytGridLine + 1
  1653.     Else
  1654.         lY& = 1
  1655.     End If
  1656.     
  1657.     If y! > 0 And y! <= lY& Then
  1658.         RowFromPoint = 0
  1659.         Exit Function
  1660.     End If
  1661.     
  1662.     RowFromPoint = -1
  1663.     For lThisRow& = lTopRow To lRows
  1664.         lMyRowHeight = lRowHeight(lThisRow&)
  1665.         If y >= lY& And y <= lY& + lMyRowHeight Then
  1666.             RowFromPoint = lThisRow&
  1667.             Exit For
  1668.         End If
  1669.         lY& = lY& + lMyRowHeight& + bytGridLine
  1670.     Next
  1671. End Function
  1672.  
  1673. Private Function ColFromPoint(x As Single, y As Single)
  1674.     Dim lX As Long, lMyColWidth As Long
  1675.     
  1676.     If bShowGrid Then
  1677.         bytGridLine = 1
  1678.     Else
  1679.         bytGridLine = 0
  1680.     End If
  1681.     
  1682.     If bRowHeader Then
  1683.         lX& = lColWidth(0) + bytGridLine + 1
  1684.     Else
  1685.         lX& = 1
  1686.     End If
  1687.     
  1688.     If x! > 0 And x! <= lX& Then
  1689.         ColFromPoint = 0
  1690.         Exit Function
  1691.     End If
  1692.     
  1693.     ColFromPoint = -1
  1694.     For lThisCol& = lLeftCol To lCols
  1695.         lMyColWidth = lColWidth(lThisCol&)
  1696.         If x >= lX& And x <= lX& + lMyColWidth Then
  1697.             ColFromPoint = lThisCol&
  1698.             Exit For
  1699.         End If
  1700.         lX& = lX& + lMyColWidth& + bytGridLine
  1701.     Next
  1702. End Function
  1703.  
  1704. Public Sub EditKeyDown(KeyCode As Integer, Shift As Integer)
  1705. Attribute EditKeyDown.VB_MemberFlags = "40"
  1706.     Dim lX As Long, lY As Long, bOver As Boolean
  1707.     Dim lMyColWidth As Long, lMyRowHeight As Long
  1708.     
  1709.     'Process the keydown
  1710.     If KeyCode = 13 Then
  1711.         If bEditMode Then
  1712.             Cells.Text(lCol, lRow) = txtEdit.Text
  1713.             bEditMode = False
  1714.             'RedrawAllCells False
  1715.             GetCellCoordinates lRow, lCol, x&, y&
  1716.             lMyColWidth = lColWidth(lCol)
  1717.             lMyRowHeight = lRowHeight(lRow)
  1718.             txtEdit.Visible = False
  1719.             txtEdit.ZOrder 1
  1720.             'raiseevent leavecell
  1721.             'picGrid.AutoRedraw = True
  1722.             DrawCell lRow, lCol, x&, y&, lMyColWidth, lMyRowHeight
  1723.             'picGrid.AutoRedraw = False
  1724.             DrawGridBorder
  1725.             HilightCell lRow, lCol
  1726.         End If
  1727.     End If
  1728.     If KeyCode = 27 Then
  1729.         If bEditMode Then
  1730.             bEditMode = False
  1731.             'RedrawAllCells False
  1732.             GetCellCoordinates lRow, lCol, x&, y&
  1733.             lMyColWidth = lColWidth(lCol)
  1734.             lMyRowHeight = lRowHeight(lRow)
  1735.             txtEdit.Visible = False
  1736.             txtEdit.ZOrder 1
  1737.             'raiseevent leavecell
  1738.             'picGrid.AutoRedraw = True
  1739.             DrawCell lRow, lCol, x&, y&, lMyColWidth, lMyRowHeight
  1740.             'picGrid.AutoRedraw = False
  1741.             DrawGridBorder
  1742.             HilightCell lRow, lCol
  1743.         End If
  1744.     End If
  1745. End Sub
  1746.  
  1747. Public Sub EditKeyPress(KeyAscii As Integer)
  1748. Attribute EditKeyPress.VB_MemberFlags = "40"
  1749.     If KeyAscii = 13 Then
  1750.         KeyAscii = 0
  1751.     End If
  1752. End Sub
  1753.  
  1754. Public Sub DblClick()
  1755.   Dim lMyColWidth As Long, lMyRowHeight As Long
  1756.   If lRow >= 0 And lCol >= 0 Then
  1757.     If lColMask(lCol) = 4 Then          'checkmark
  1758.       If Cells.Text(lCol, lRow) = "1" Then
  1759.         Cells.Text(lCol, lRow) = "0"
  1760.       Else
  1761.         Cells.Text(lCol, lRow) = "1"
  1762.       End If
  1763.             GetCellCoordinates lRow, lCol, x&, y&
  1764.             lMyColWidth = lColWidth(lCol)
  1765.             lMyRowHeight = lRowHeight(lRow)
  1766.             DrawCell lRow, lCol, x&, y&, lMyColWidth, lMyRowHeight
  1767.             DrawGridBorder
  1768.             HilightCell lRow, lCol
  1769.     Else
  1770.       GridEdit Asc(" ")
  1771.     End If
  1772.   End If
  1773. End Sub
  1774.  
  1775. Public Sub MouseUp(button As Integer, Shift As Integer, x As Single, y As Single)
  1776. Attribute MouseUp.VB_MemberFlags = "40"
  1777.     bMouseDown = False
  1778.     bSelectingRows = False
  1779.     bSelectingCols = False
  1780.     picSizer.Visible = False
  1781.     
  1782.     If bSizingCol Then
  1783.         If lCurrentColSizer& > 1 Then
  1784.             lNewWidth = picSizer.Left - hSizers(lCurrentColSizer& - 1)
  1785.         Else
  1786.             lNewWidth = picSizer.Left
  1787.         End If
  1788.         If lNewWidth < 0 Then lNewWidth = 10            'changed default to 10 from 0
  1789.         If bRowHeader Then
  1790.             ColWidth(lLeftCol + lCurrentColSizer& - 2) = lNewWidth
  1791.         Else
  1792.             ColWidth(lLeftCol + lCurrentColSizer& - 1) = lNewWidth
  1793.         End If
  1794.         ShowLookup
  1795.     End If
  1796.     bSizingCol = False
  1797.     
  1798. '    If bSizingRow Then
  1799. '        If lCurrentRowSizer& > 1 Then
  1800. '            lNewHeight = picSizer.Top - vSizers(lCurrentRowSizer& - 1)
  1801. '        Else
  1802. '            lNewHeight = picSizer.Top
  1803. '        End If
  1804. '        If lNewHeight < 0 Then lNewHeight = 0
  1805. '        RowHeight(lTopRow + lCurrentRowSizer - 2) = lNewHeight
  1806. '    End If
  1807.     bSizingRow = False
  1808. End Sub
  1809.  
  1810. Public Sub MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
  1811. Attribute MouseMove.VB_MemberFlags = "40"
  1812.     Dim lpRect As RECT, bytPointer As Byte
  1813.     Dim lScaleWidth As Integer, lScaleHeight As Integer
  1814.     Dim bShouldRedraw As Boolean, lNewCol2 As Long, lNewRow2 As Long
  1815.     Dim lPt As POINTAPI
  1816.     
  1817.     lScaleWidth = picGrid.ScaleWidth
  1818.     lScaleHeight = picGrid.ScaleHeight
  1819.     
  1820.     lNewRow2 = RowFromPoint(x, y)
  1821.     lNewCol2 = ColFromPoint(x, y)
  1822.     
  1823.     If bSizingCol Then
  1824.         If scrVertical.Visible Then
  1825.             lRightEdge = scrVertical.Left - 1
  1826.         Else
  1827.             lRightEdge = lScaleWidth
  1828.         End If
  1829.         
  1830.         If x <= lRightEdge Then picSizer.Left = x
  1831.     
  1832.     ElseIf bSizingRow Then
  1833.         If scrHorizontal.Visible Then
  1834.             lBottomEdge = scrHorizontal.Top - 1
  1835.         Else
  1836.             lBottomEdge = lScaleHeight
  1837.         End If
  1838.         
  1839.         If y <= lBottomEdge Then picSizer.Top = y
  1840.     
  1841.     ElseIf bMouseDown And bAllowSelection And iSelectionMode = 0 Then
  1842.         If bSelectingRows = True Or bSelectingCols = True Then
  1843.             'Select more rows
  1844.         Else
  1845.             'See if they're selecting multiple cells
  1846.             'picGrid.AutoRedraw = True
  1847.             bRedraw = False
  1848.             bShouldRedraw = False
  1849.             bMouseHit = False
  1850.             
  1851.             'See if we need to auto scroll up
  1852.             If y < 0 Or lNewRow2 = 0 Then
  1853.                 If scrVertical.Value > 1 Then scrVertical = scrVertical - 1
  1854.                 lNewRow2 = lTopRow
  1855.                 bShouldRedraw = True
  1856.                 bMouseHit = True
  1857.             End If
  1858.             
  1859.             'See if we need to auto scroll left
  1860.             If x < 0 Or lNewCol2 = 0 Then
  1861.                 If scrHorizontal.Value > 1 Then scrHorizontal = scrHorizontal - 1
  1862.                 lNewCol2 = lLeftCol
  1863.                 bShouldRedraw = True
  1864.                 bMouseHit = True
  1865.             End If
  1866.             
  1867.             'See if we need to auto scroll right
  1868.             If lNewCol2 < 0 Then lNewCol2 = 0
  1869.             If x > lScaleWidth Then
  1870.                 If scrHorizontal.Value < scrHorizontal.Max Then
  1871.                     scrHorizontal.Value = scrHorizontal.Value + 1
  1872.                     bShouldRedraw = True
  1873.                 End If
  1874.                 bMouseHit = True
  1875.             End If
  1876.             
  1877.             'See if we need to auto scroll down
  1878.             If lNewRow2 < 0 Then lNewRow2 = 0
  1879.             If y > lScaleHeight Then
  1880.                 If scrVertical.Value < scrVertical.Max Then
  1881.                     scrVertical.Value = scrVertical.Value + 1
  1882.                     bShouldRedraw = True
  1883.                 End If
  1884.                 bMouseHit = True
  1885.             End If
  1886.             
  1887.             'Now find out if we need to hilight the selection
  1888.             If lNewRow2 = lRow2 And lNewCol2 = lCol2 Then
  1889.                 'do nothing
  1890.             Else
  1891.                 'Un-hilight the old selection
  1892.                 HilightSelection lRow1, lCol1, lRow2, lCol2
  1893.                 'Hilight the new selection
  1894.                 lRow2 = lNewRow2
  1895.                 lCol2 = lNewCol2
  1896.                 HilightSelection lRow1, lCol1, lRow2, lCol2
  1897.                 
  1898.                 bShouldRedraw = True
  1899.             End If
  1900.             bRedraw = True
  1901.             
  1902.             If bShouldRedraw Then picGrid.Refresh
  1903.             'picGrid.AutoRedraw = False
  1904.             
  1905.             If bMouseHit Then
  1906.                 GetCursorPos lPt
  1907.                 SetCursorPos lPt.x, lPt.y
  1908.             End If
  1909.         End If
  1910.     Else
  1911.         If bColHeader = True And lNewRow2 = 0 Then
  1912.             'If the X is within one of the sizers, change the mouse pointer to a sizer
  1913.             lCurrentColSizer& = -1
  1914.             For lCount& = 1 To hSizers.Count
  1915.                 If Abs(hSizers(lCount&) - x) < 2 Then
  1916.                     'It's within 2 pixels of a sizer, so set the MousePointer
  1917.                     lCurrentColSizer& = lCount&
  1918.                     Exit For
  1919.                 End If
  1920.             Next
  1921.             
  1922.             If lCurrentColSizer& > -1 Then
  1923.                 UserControl.MousePointer = vbSizeWE
  1924.             Else
  1925.                 UserControl.MousePointer = vbDefault
  1926.             End If
  1927. '        ElseIf bRowHeader = True And lNewCol2 = 0 Then
  1928. '            'If the Y is within one of the sizers, change the mouse pointer to a sizer
  1929. '            lCurrentRowSizer& = -1
  1930. '            For lCount& = 1 To vSizers.Count
  1931. '                If Abs(vSizers(lCount&) - y) < 2 Then
  1932. '                    'It's within 2 pixels of a sizer, so set the MousePointer
  1933. '                    lCurrentRowSizer& = lCount&
  1934. '                    Exit For
  1935. '                End If
  1936. '            Next
  1937. '
  1938. '            If lCurrentRowSizer& > -1 Then
  1939. '                UserControl.MousePointer = vbSizeNS
  1940. '            Else
  1941. '                UserControl.MousePointer = vbDefault
  1942. '            End If
  1943.         Else
  1944.             UserControl.MousePointer = vbDefault
  1945.         End If
  1946.     End If
  1947.     
  1948. MouseMoveExit:
  1949.     
  1950. End Sub
  1951.  
  1952. Public Sub HilightSelection(Optional Row1, Optional Col1, Optional Row2, Optional Col2)
  1953. Attribute HilightSelection.VB_MemberFlags = "40"
  1954.     Dim lpRect As RECT
  1955.     Dim lThisRow As Long, lThisCol As Long
  1956.     Dim lMyRowHeight As Long, lMyColWidth As Long
  1957.     Dim x1 As Long, y1 As Long, lCol1Width As Long, lRow1Height As Long
  1958.     Dim x2 As Long, Y2 As Long
  1959.     
  1960.     'picGrid.AutoRedraw = True
  1961.     
  1962.     If IsMissing(Row1) Then Row1 = lRow1
  1963.     If IsMissing(Col1) Then Col1 = lCol1
  1964.     If IsMissing(Row2) Then Row2 = lRow2
  1965.     If IsMissing(Col2) Then Col2 = lCol2
  1966.     
  1967.     If lRows < 1 Or lCols < 1 Then Exit Sub         'kdq090298
  1968.     If Row1 < lTopRow And Row2 < lTopRow Then Exit Sub
  1969.     If Col1 < lLeftCol And Col2 < lLeftCol Then Exit Sub
  1970.     
  1971.     bOver = GetCellCoordinates(Row1, Col1, x1&, y1&)
  1972.     bOver = GetCellCoordinates(Row2, Col2, x2&, Y2&)
  1973.     
  1974.     If Col2 < Col1 Then
  1975.         lpRect.Left = x2
  1976.         lpRect.Right = x1 + lColWidth(Col1)
  1977.         If Col2 > lLeftCol Then lpRect.Left = lpRect.Left - 2
  1978.     Else
  1979.         lpRect.Left = x1
  1980.         lpRect.Right = x2 + lColWidth(Col2)
  1981.         If Col1 > lLeftCol Then lpRect.Left = lpRect.Left - 2
  1982.     End If
  1983.     
  1984.     If Row2 < Row1 Then
  1985.         lpRect.Top = Y2
  1986.         lpRect.Bottom = y1 + lRowHeight(Row1)
  1987.         If Row2 > lTopRow Then lpRect.Top = lpRect.Top - 2
  1988.     Else
  1989.         lpRect.Top = y1
  1990.         lpRect.Bottom = Y2 + lRowHeight(Row2)
  1991.         If Row1 > lTopRow Then lpRect.Top = lpRect.Top - 2
  1992.     End If
  1993.     
  1994.     If bShowGrid Then
  1995.         lpRect.Right = lpRect.Right + 2
  1996.         lpRect.Bottom = lpRect.Bottom + 2
  1997.     End If
  1998.     
  1999.     'Invert the hilighted rect
  2000.     InvertRect picGrid.hDC, lpRect
  2001.     
  2002.     'Fix any hilighting of the bottom and right stuff
  2003.     'DrawBottomRight
  2004.     'Draw the blank grey box at the end of the scroll bars
  2005.     If (bWidthOverflow And bHeightOverflow) Or (scrHorizontal.Visible And scrVertical.Visible) Then DrawBox lScaleWidth - 20, lScaleHeight - 20, 20, 20, COLOR_GREY
  2006.     
  2007.     If bRedraw Then picGrid.Refresh
  2008.     'picGrid.AutoRedraw = False
  2009. End Sub
  2010.  
  2011. Private Function GetCellCoordinates(ThisRow, ThisCol, x As Long, y As Long) As Boolean
  2012.     Dim lScaleWidth As Long, lScaleHeight As Long
  2013.     Dim lMyColWidth As Long, lMyRowHeight As Long
  2014.     
  2015.     lScaleWidth = picGrid.ScaleWidth
  2016.     lScaleHeight = picGrid.ScaleHeight
  2017.     
  2018.     'Assume it's not on the screen
  2019.     If bColHeader Then
  2020.         y& = lRowHeight(0) + bytGridLine + 1
  2021.     Else
  2022.         y& = 1
  2023.     End If
  2024.     
  2025.     If bRowHeader Then
  2026.         x& = lColWidth(0) + bytGridLine + 1
  2027.     Else
  2028.         x& = 1
  2029.     End If
  2030.     
  2031. '    'See if the current cell is possibly visible
  2032. '    If ThisRow >= lTopRow And ThisCol >= lLeftCol Then
  2033.         If bShowGrid Then
  2034.             bytGridLine = 1
  2035.         Else
  2036.             bytGridLine = 0
  2037.         End If
  2038.         
  2039.         'Now see if the selected row is on the screen
  2040.         bRowOver = False
  2041.         For lCurRow& = lTopRow& To ThisRow
  2042.             If y& > lScaleHeight - 1 Then
  2043.                 bRowOver = True
  2044.                 Exit For
  2045.             End If
  2046.             If lCurRow& < ThisRow Then y& = y& + lRowHeight(lCurRow&) + bytGridLine
  2047.         Next
  2048.         
  2049.         'If Not bOver Then
  2050.             'Now find out if the selected col is on the screen
  2051.             bColOver = False
  2052.             For lCurCol& = lLeftCol& To ThisCol
  2053.                 If x& > lScaleWidth - 1 Then
  2054.                     bColOver = True
  2055.                     Exit For
  2056.                 End If
  2057.                 If lCurCol& < ThisCol Then x& = x& + lColWidth(lCurCol&) + bytGridLine
  2058.             Next
  2059.         'End If
  2060. '    Else
  2061. '        bOver = True
  2062. '    End If
  2063.     
  2064.     If bColOver = True Or bRowOver = True Then
  2065.         GetCellCoordinates = True
  2066.     Else
  2067.         GetCellCoordinates = False
  2068.     End If
  2069. End Function
  2070.  
  2071. Private Sub RedrawCells(lpRect As RECT)
  2072.     Dim x As Long, y As Long
  2073.     Dim lMyColWidth As Long, lMyRowHeight As Long
  2074.     Dim lThisRow As Long, lThisCol As Long
  2075.     
  2076.     For lThisRow = lpRect.Top To lpRect.Bottom
  2077.         For lThisCol = lpRect.Left To lpRect.Right
  2078.             GetCellCoordinates lThisRow, lThisCol, x&, y&
  2079.             lMyColWidth = lColWidth(lThisCol)
  2080.             lMyRowHeight = lRowHeight(lThisRow)
  2081.             
  2082.             DrawCell lThisRow, lThisCol, x&, y&, lMyColWidth, lMyRowHeight, False
  2083.             'UserControl.Refresh
  2084.         Next
  2085.     Next
  2086. End Sub
  2087.  
  2088. Private Sub DrawBottomRight()
  2089.     Dim lScaleWidth As Long, lScaleHeight As Long
  2090.     Dim lpRect As RECT
  2091.     
  2092.     lScaleWidth = picGrid.ScaleWidth
  2093.     lScaleHeight = picGrid.ScaleHeight
  2094.     
  2095.     'Draw the line on the right
  2096.     lpRect.Left = lScaleWidth - 1
  2097.     lpRect.Top = 1
  2098.     lpRect.Right = lpRect.Left
  2099.     lpRect.Bottom = lScaleHeight
  2100.     DrawLine lpRect, vbBlack
  2101.     
  2102.     'Draw the line on the bottom
  2103.     lpRect.Left = 0
  2104.     lpRect.Top = lScaleHeight - 1
  2105.     lpRect.Right = lScaleWidth
  2106.     lpRect.Bottom = lpRect.Top
  2107.     DrawLine lpRect, vbBlack
  2108.     
  2109.     'Draw the blank grey box at the end of the scroll bars
  2110.     'If Val(scrVertical.Tag) = True And Val(scrHorizontal.Tag) = True Then DrawBox lScaleWidth - 20, lScaleHeight - 20, 19, 19, COLOR_GREY
  2111. End Sub
  2112.  
  2113. Public Sub KeyDown(KeyCode As Integer, Shift As Integer)
  2114. Attribute KeyDown.VB_MemberFlags = "40"
  2115.     Dim lScrollWidth As Long, lScrollHeight As Long
  2116.     Dim lMyColWidth As Long, lMyRowHeight As Long
  2117.     
  2118.     'picGrid.AutoRedraw = True
  2119.     
  2120.     If KeyCode = vbKeyLeft Then
  2121.         If lCol > 1 Then
  2122.             HilightCell
  2123.             lCol = lCol - 1
  2124.             
  2125.             If lCol < lLeftCol Then
  2126.                 If scrHorizontal.Value > 1 Then
  2127.                     scrHorizontal.Value = scrHorizontal.Value - 1
  2128.                 Else
  2129.                     HilightCell
  2130.                 End If
  2131.             Else
  2132.                 HilightCell
  2133.             End If
  2134.             'FireEvent 1
  2135.         End If
  2136.     ElseIf KeyCode = vbKeyUp Then
  2137.         If lRow > 1 Then
  2138.             HilightCell
  2139.             lRow = lRow - 1
  2140.             
  2141.             If lRow < lTopRow Then
  2142.                 If scrVertical.Value > 1 Then
  2143.                     scrVertical.Value = scrVertical.Value - 1
  2144.                 Else
  2145.                     HilightCell
  2146.                 End If
  2147.             Else
  2148.                 HilightCell
  2149.             End If
  2150.             'FireEvent 1
  2151.         End If
  2152.     ElseIf KeyCode = vbKeyRight Then
  2153.         If lCol < lCols Then
  2154.             HilightCell
  2155.             lCol = lCol + 1
  2156.             
  2157.             bOver = GetCellCoordinates(lRow, lCol, lX&, lY&)
  2158.             If scrVertical.Visible Then
  2159.                 lScrollWidth = scrVertical.Width
  2160.             Else
  2161.                 lScrollWidth = 0
  2162.             End If
  2163.             lMyColWidth = lColWidth(lCol)
  2164.             If lX& > (picGrid.ScaleWidth - lMyColWidth - lScrollWidth) Then
  2165.                 If scrHorizontal.Value < scrHorizontal.Max Then
  2166.                     HilightCell
  2167.                     
  2168.                     scrHorizontal.Value = scrHorizontal.Value + 1
  2169.                 Else
  2170.                     HilightCell
  2171.                 End If
  2172.             Else
  2173.                 HilightCell
  2174.             End If
  2175.             'FireEvent 1
  2176.         End If
  2177.     ElseIf KeyCode = vbKeyDown Then
  2178.         If lRow < lRows Then
  2179.             HilightCell
  2180.             lRow = lRow + 1
  2181.             
  2182.             bOver = GetCellCoordinates(lRow, lCol, lX&, lY&)
  2183.             If scrHorizontal.Visible Then
  2184.                 lScrollHeight = scrHorizontal.Height
  2185.             Else
  2186.                 lScrollHeight = 0
  2187.             End If
  2188.             lMyRowHeight = lRowHeight(lRow)
  2189.             If lY& > (picGrid.ScaleHeight - lMyRowHeight - lScrollHeight) Then
  2190.                 If scrVertical.Value < scrVertical.Max Then
  2191.                     HilightCell
  2192.                     
  2193.                     scrVertical.Value = scrVertical.Value + 1
  2194.                 Else
  2195.                     HilightCell
  2196.                 End If
  2197.             Else
  2198.                 HilightCell
  2199.             End If
  2200.             'FireEvent 1
  2201.         End If
  2202.     End If
  2203.     
  2204.     If KeyCode = vbKeyLeft Or KeyCode = vbKeyRight Or KeyCode = vbKeyUp Or KeyCode = vbKeyDown Then
  2205.         If txtEdit.Visible Then
  2206.             txtEdit.Visible = False
  2207.             'raiseevent leavecell
  2208.             RaiseEvent AfterEdit(lRow, lCol, Text)
  2209.         End If
  2210.         List1.Visible = False
  2211.         cmdLookup.Visible = False
  2212.         ShowLookup
  2213.     End If
  2214.     If bRedraw Then picGrid.Refresh
  2215.     'picGrid.AutoRedraw = False
  2216. End Sub
  2217.  
  2218. Public Function GetColWidth(lThisCol&) As Long
  2219. Attribute GetColWidth.VB_MemberFlags = "40"
  2220.     GetColWidth = lColWidth(lThisCol&)
  2221. End Function
  2222.  
  2223. Public Sub SetColWidth(lThisCol&, lNewColWidth&)
  2224. Attribute SetColWidth.VB_MemberFlags = "40"
  2225.     lColWidth(lThisCol&) = lNewColWidth&
  2226.     RedrawAllCells True
  2227. End Sub
  2228.  
  2229. Public Function BlockSelected() As Boolean
  2230. Attribute BlockSelected.VB_MemberFlags = "40"
  2231.     If lRow2 <> lRow1 Or lCol2 <> lCol1 Then
  2232.         BlockSelected = True
  2233.     Else
  2234.         BlockSelected = False
  2235.     End If
  2236. End Function
  2237.  
  2238. Public Property Get Row1() As Long
  2239. Attribute Row1.VB_MemberFlags = "440"
  2240.     Row1 = lRow1
  2241. End Property
  2242.  
  2243. Public Property Let Row1(lNewValue As Long)
  2244.     lRow1 = lNewValue
  2245. End Property
  2246.  
  2247. Public Property Get Col1() As Long
  2248. Attribute Col1.VB_MemberFlags = "440"
  2249.     Col1 = lCol1
  2250. End Property
  2251.  
  2252. Public Property Let Col1(lNewValue As Long)
  2253.     lCol1 = lNewValue
  2254. End Property
  2255.  
  2256. Public Property Get Row2() As Long
  2257. Attribute Row2.VB_MemberFlags = "440"
  2258.     Row2 = lRow2
  2259. End Property
  2260.  
  2261. Public Property Let Row2(lNewValue As Long)
  2262.     lRow2 = lNewValue
  2263. End Property
  2264.  
  2265. Public Property Get Col2() As Long
  2266. Attribute Col2.VB_MemberFlags = "440"
  2267.     Col2 = lCol2
  2268. End Property
  2269.  
  2270. Public Property Let Col2(lNewValue As Long)
  2271.     lCol2 = lNewValue
  2272. End Property
  2273.  
  2274. 'Public Property Get Name() As String
  2275. '    Name = sName$
  2276. 'End Property
  2277. '
  2278. 'Public Property Let Name(sNewValue As String)
  2279. '    sName$ = sNewValue$
  2280. 'End Property
  2281.  
  2282. Private Sub picGrid_DblClick()
  2283.     DblClick
  2284. End Sub
  2285.  
  2286. Private Sub picGrid_KeyDown(KeyCode As Integer, Shift As Integer)
  2287.     RaiseEvent KeyDown(KeyCode, Shift)
  2288.     KeyDown KeyCode, Shift
  2289. End Sub
  2290.  
  2291. Private Sub picGrid_KeyPress(KeyAscii As Integer)
  2292.    RaiseEvent KeyPress(KeyAscii)
  2293.    If Cols > 0 And Rows > 0 And KeyAscii <> vbKeyTab Then
  2294.      GridEdit KeyAscii
  2295.    End If
  2296.  
  2297. End Sub
  2298.  
  2299. Private Sub picGrid_KeyUp(KeyCode As Integer, Shift As Integer)
  2300.   RaiseEvent KeyUp(KeyCode, Shift)
  2301. End Sub
  2302.  
  2303. Private Sub picGrid_MouseDown(button As Integer, Shift As Integer, x As Single, y As Single)
  2304.     MouseDown button, Shift, x, y
  2305.     RaiseEvent MouseDown(button, Shift, x, y)
  2306. End Sub
  2307.  
  2308. Private Sub picGrid_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
  2309.     MouseMove button, Shift, x, y
  2310.     RaiseEvent MouseMove(button, Shift, x, y)
  2311. End Sub
  2312.  
  2313. Private Sub picGrid_MouseUp(button As Integer, Shift As Integer, x As Single, y As Single)
  2314.     MouseUp button, Shift, x, y
  2315.     RaiseEvent MouseUp(button, Shift, x, y)
  2316. End Sub
  2317.  
  2318. Private Sub scrHorizontal_Change()
  2319.     HChange
  2320.     If txtEdit.Visible Then
  2321.       txtEdit.Visible = False
  2322.       'raiseevent leavecell
  2323.       RaiseEvent AfterEdit(lRow, lCol, Text)
  2324.     End If
  2325.     List1.Visible = False
  2326.     cmdLookup.Visible = False
  2327.     ShowLookup
  2328. End Sub
  2329.  
  2330. Private Sub scrHorizontal_GotFocus()
  2331.   'kdq 083198       added so scrollbars do not get focus
  2332.   picGrid.SetFocus
  2333. End Sub
  2334.  
  2335. Private Sub scrVertical_Change()
  2336.     VChange
  2337.     If txtEdit.Visible Then
  2338.         txtEdit.Visible = False
  2339.         'raiseevent leavecell
  2340.         RaiseEvent AfterEdit(lRow, lCol, Text)
  2341.     End If
  2342.     List1.Visible = False
  2343.     cmdLookup.Visible = False
  2344.     ShowLookup
  2345. End Sub
  2346.  
  2347. Private Sub scrVertical_GotFocus()
  2348.   'kdq 083198       added so scrollbars do not get focus
  2349.   picGrid.SetFocus
  2350. End Sub
  2351.  
  2352. Private Sub txtEdit_KeyDown(KeyCode As Integer, Shift As Integer)
  2353.     EditKeyDown KeyCode, Shift
  2354. End Sub
  2355.  
  2356. Private Sub txtEdit_KeyPress(KeyAscii As Integer)
  2357.   Select Case ColMask(lCol)
  2358.   Case 0        'no mask
  2359.   Case 1        'Uppercase
  2360.     KeyAscii = Asc(UCase(Chr(KeyAscii)))
  2361.   Case 2        'Numeric only
  2362.     KeyAscii = NumOnly(KeyAscii)
  2363.   Case 3        'Date only
  2364.     KeyAscii = DateOnly(KeyAscii)
  2365.   End Select
  2366. End Sub
  2367.  
  2368. Private Sub UserControl_DblClick()
  2369.     DblClick
  2370. End Sub
  2371.  
  2372. Private Sub UserControl_ExitFocus()
  2373.     If bEditMode Then
  2374.         HideEdit
  2375.         HilightCell
  2376.     End If
  2377. End Sub
  2378.  
  2379. Private Sub UserControl_Initialize()
  2380.     Set Cells = New clsCellArray
  2381.     Set txtEdit.Font = picGrid.Font
  2382.     Set hSizers = New Collection
  2383.     Set vSizers = New Collection
  2384.     
  2385.     'kdq083198      changed these lines to accomodate new borderstyles
  2386.     'scrHorizontal.Move 2, UserControl.ScaleHeight - 21, UserControl.ScaleWidth - 22, 18
  2387.     'scrVertical.Move UserControl.ScaleWidth - 21, 2, 18, UserControl.ScaleHeight - 22
  2388.     'picGrid.Move 2, 2, scrVertical.Left, scrHorizontal.Top
  2389.     
  2390.     lLeftCol = 1
  2391.     lTopRow = 1
  2392.  
  2393.     lRow = 1
  2394.     lCol = 1
  2395.     lRow1 = 1
  2396.     lCol1 = 1
  2397.     lRow2 = 1
  2398.     lCol2 = 1
  2399. End Sub
  2400.  
  2401. Private Sub UserControl_InitProperties()
  2402.     'Turn on headers
  2403.     bColHeader = True
  2404.     bRowHeader = True
  2405.     bShowGrid = True
  2406.     bGridSolid = True
  2407.     lGridLineColor = COLOR_GREY
  2408.     bColSizing = True
  2409.     bRowSizing = True
  2410.     bSizingCol = False
  2411.     bSizingRow = False
  2412.     bAllowUserResizing = True
  2413.     sFormatString = ""
  2414.     bAutoNewRow = False
  2415.     m_ListBoxRows = 6
  2416.  
  2417.     iBorderStyle = 1
  2418.     lBackColor = vbWhite
  2419.     lBackColorFixed = COLOR_GREY
  2420.     lBackColorBkg = COLOR_DARKGREY
  2421.     lForeColor = vbButtonText
  2422.     lForeColorFixed = vbButtonText
  2423.     bAllowSelection = True
  2424.     iFixedStyle = 1
  2425.     iSelectionMode = 0
  2426.     
  2427.     Set fFont = Ambient.Font
  2428.     Set fFontFixed = Ambient.Font
  2429.     fFontFixed.Bold = True
  2430.     
  2431.     'Set up columns and rows
  2432.     Cols = 5
  2433.     Rows = 1
  2434.  
  2435.     lLeftCol = 1
  2436.     lTopRow = 1
  2437.  
  2438.     lRow = 1
  2439.     lCol = 1
  2440.     lRow1 = 1
  2441.     lCol1 = 1
  2442.     lRow2 = 1
  2443.     lCol2 = 1
  2444.  
  2445.     bRedraw = True
  2446.     m_DataSource = m_def_DataSource
  2447. '    m_RecordSource = m_def_RecordSource
  2448.     m_Recordset = m_def_Recordset
  2449. End Sub
  2450.  
  2451. Private Sub UserControl_KeyDown(KeyCode As Integer, Shift As Integer)
  2452.     KeyDown KeyCode, Shift
  2453. End Sub
  2454.  
  2455. Private Sub UserControl_MouseDown(button As Integer, Shift As Integer, x As Single, y As Single)
  2456.     MouseDown button, Shift, x, y
  2457. End Sub
  2458.  
  2459. Private Sub UserControl_MouseMove(button As Integer, Shift As Integer, x As Single, y As Single)
  2460.     MouseMove button, Shift, x, y
  2461. End Sub
  2462.  
  2463. Private Sub UserControl_MouseUp(button As Integer, Shift As Integer, x As Single, y As Single)
  2464.    MouseUp button, Shift, x, y
  2465. End Sub
  2466.  
  2467. Private Sub UserControl_Paint()
  2468.     Dim di As Long
  2469.     Dim rc As RECT
  2470.     Dim xTwips As Integer, yTwips As Integer
  2471.     
  2472.     xTwips = Screen.TwipsPerPixelX
  2473.     yTwips = Screen.TwipsPerPixelY
  2474.     
  2475.     'draw outside border
  2476.         
  2477.     'get dimensions of usercontrol
  2478.     di = GetClientRect(UserControl.hwnd, rc)
  2479.     
  2480.     Select Case iBorderStyle
  2481.         Case [No Border]
  2482.         
  2483.         Case [Single]
  2484.             di = DrawEdge(UserControl.hDC, rc, BDR_RAISEDOUTER, BF_RECT Or BF_MONO)
  2485.             
  2486.         Case [Thin Raised]
  2487.             di = DrawEdge(UserControl.hDC, rc, BDR_RAISEDINNER, BF_TOPLEFT)
  2488.             di = DrawEdge(UserControl.hDC, rc, BDR_RAISEDOUTER, BF_BOTTOMRIGHT)
  2489.         
  2490.         Case [Thick Raised]
  2491.             di = DrawEdge(UserControl.hDC, rc, EDGE_RAISED, BF_TOPLEFT)
  2492.             di = DrawEdge(UserControl.hDC, rc, EDGE_RAISED, BF_BOTTOMRIGHT)
  2493.     
  2494.         Case [Thin Inset]
  2495.             di = DrawEdge(UserControl.hDC, rc, BDR_SUNKENINNER, BF_TOPLEFT)
  2496.             di = DrawEdge(UserControl.hDC, rc, BDR_SUNKENOUTER, BF_BOTTOMRIGHT)
  2497.         
  2498.         Case [Thick Inset]
  2499.             di = DrawEdge(UserControl.hDC, rc, EDGE_SUNKEN, BF_TOPLEFT)
  2500.             di = DrawEdge(UserControl.hDC, rc, EDGE_SUNKEN, BF_BOTTOMRIGHT)
  2501.         
  2502.         Case [Etched]
  2503.             di = DrawEdge(UserControl.hDC, rc, EDGE_ETCHED, BF_TOPLEFT)
  2504.             di = DrawEdge(UserControl.hDC, rc, EDGE_ETCHED, BF_BOTTOMRIGHT)
  2505.     
  2506.         Case [Bump]
  2507.             di = DrawEdge(UserControl.hDC, rc, EDGE_BUMP, BF_TOPLEFT)
  2508.             di = DrawEdge(UserControl.hDC, rc, EDGE_BUMP, BF_BOTTOMRIGHT)
  2509.             
  2510.     End Select
  2511.     
  2512. End Sub
  2513.  
  2514. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  2515. Dim totcnt As Integer, cnt As Integer
  2516. Dim Index As Integer
  2517. Dim pCol As Integer, pVal As String
  2518.     
  2519.     Rows = PropBag.ReadProperty("Rows", 10)
  2520.     Cols = PropBag.ReadProperty("Cols", 10)
  2521.     Row = PropBag.ReadProperty("Row", 1)
  2522.     Col = PropBag.ReadProperty("Col", 1)
  2523.     bShowGrid = PropBag.ReadProperty("ShowGrid", True)
  2524.     bGridSolid = PropBag.ReadProperty("GridSolid", True)
  2525.     lGridLineColor = PropBag.ReadProperty("GridLineColor", vbButtonFace)
  2526.     bRedraw = PropBag.ReadProperty("Redraw", True)
  2527.     iBorderStyle = PropBag.ReadProperty("BorderStyle", m_BorderStyle_Def)
  2528.     UserControl.MousePointer = PropBag.ReadProperty("MousePointer", 0)
  2529.     m_DataSource = PropBag.ReadProperty("DataSource", m_def_DataSource)
  2530. '    m_RecordSource = PropBag.ReadProperty("RecordSource", m_def_RecordSource)
  2531.     m_Recordset = PropBag.ReadProperty("Recordset", m_def_Recordset)
  2532.     bAllowSelection = PropBag.ReadProperty("AllowSelection", True)
  2533.     lBackColor = PropBag.ReadProperty("BackColor", vbWhite)
  2534.     lBackColorFixed = PropBag.ReadProperty("BackColorFixed", vbButtonFace)
  2535.     'lBackColorSel = PropBag.ReadProperty("BackColorSel", vbHighlight)
  2536.     lForeColor = PropBag.ReadProperty("ForeColor", vbButtonText)
  2537.     lForeColorFixed = PropBag.ReadProperty("ForeColorFixed", vbButtonText)
  2538.     'lForeColorSel = PropBag.ReadProperty("ForeColorSel", vbButtonText)
  2539.     iFixedStyle = PropBag.ReadProperty("FixedStyle", 1)
  2540.     bColHeader = PropBag.ReadProperty("ColHeader", True)
  2541.     bRowHeader = PropBag.ReadProperty("RowHeader", True)
  2542.     iSelectionMode = PropBag.ReadProperty("SelectionMode", 0)
  2543.     UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
  2544.     Set fFont = PropBag.ReadProperty("Font", Ambient.Font)
  2545.     Set fFontFixed = PropBag.ReadProperty("FontFixed", Ambient.Font)
  2546.     lBackColorBkg = PropBag.ReadProperty("BackColorBkg", COLOR_DARKGREY)
  2547.     bAllowUserResizing = PropBag.ReadProperty("AllowUserResizing", True)
  2548.     sFormatString = PropBag.ReadProperty("FormatString", "")
  2549.     bAutoNewRow = PropBag.ReadProperty("AutoNewRow", False)
  2550.     m_ListBoxRows = PropBag.ReadProperty("ListBoxRows", 6)
  2551.     totcnt = PropBag.ReadProperty("Count", 0)
  2552.     For Index = 1 To totcnt
  2553.       pCol = PropBag.ReadProperty("Column" & Index)
  2554.       pVal = PropBag.ReadProperty("Value" & Index)
  2555.       AddLookup pCol, pVal
  2556.     Next
  2557.     UpdateHeader
  2558.     Refresh
  2559. End Sub
  2560.  
  2561. Private Sub UserControl_Resize()
  2562.     'kdq083198      changed these lines to accomodate new borderstyles
  2563.     scrHorizontal.Move 2, UserControl.ScaleHeight - 21, UserControl.ScaleWidth - 23, 18
  2564.     scrVertical.Move UserControl.ScaleWidth - 21, 2, 18, UserControl.ScaleHeight - 23
  2565.     'picGrid.Move 2, 2, scrVertical.Left, scrHorizontal.Top
  2566.     picGrid.Move 2, 2, UserControl.ScaleWidth - 5, UserControl.ScaleHeight - 5
  2567.     
  2568.     'kdq083198      added so cells get redrawn properly when grid is resized
  2569.     Refresh
  2570.     
  2571.     'kdq083198      added to draw borderstyles
  2572.     UserControl.Cls
  2573.     UserControl_Paint
  2574. End Sub
  2575.  
  2576. Private Sub UserControl_Terminate()
  2577.     Set Cells = Nothing
  2578.     Set hSizers = Nothing
  2579.     Set vSizers = Nothing
  2580.     Erase lRowHeight
  2581.     Erase lColWidth
  2582.     Erase bColEdit
  2583. End Sub
  2584.  
  2585. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  2586.     Dim Index As Integer
  2587.     PropBag.WriteProperty "Rows", Rows, 10
  2588.     PropBag.WriteProperty "Cols", Cols, 10
  2589.     PropBag.WriteProperty "Row", Row, 1
  2590.     PropBag.WriteProperty "Col", Col, 1
  2591.     PropBag.WriteProperty "Redraw", bRedraw
  2592.     PropBag.WriteProperty "ShowGrid", bShowGrid
  2593.     PropBag.WriteProperty "GridSolid", bGridSolid
  2594.     PropBag.WriteProperty "GridLineColor", GridLineColor
  2595.     Call PropBag.WriteProperty("BorderStyle", iBorderStyle, m_BorderStyle_Def)
  2596.     Call PropBag.WriteProperty("MousePointer", UserControl.MousePointer, 0)
  2597.     Call PropBag.WriteProperty("DataSource", m_DataSource, m_def_DataSource)
  2598. '    Call PropBag.WriteProperty("RecordSource", m_RecordSource, m_def_RecordSource)
  2599.     Call PropBag.WriteProperty("Recordset", m_Recordset, m_def_Recordset)
  2600.     
  2601.     Call PropBag.WriteProperty("AllowSelection", bAllowSelection, True)
  2602.     Call PropBag.WriteProperty("BackColor", lBackColor, vbWhite)
  2603.     Call PropBag.WriteProperty("BackColorFixed", lBackColorFixed, vbButtonFace)
  2604.     'Call PropBag.WriteProperty("BackColorSel", lBackColorSel, vbHighlight)
  2605.     Call PropBag.WriteProperty("ForeColor", lForeColor, vbButtonText)
  2606.     Call PropBag.WriteProperty("ForeColorFixed", lForeColorFixed, vbButtonText)
  2607.     'Call PropBag.WriteProperty("ForeColorSel", lForeColorSel, vbButtonText)
  2608.     Call PropBag.WriteProperty("FixedStyle", iFixedStyle, 1)
  2609.     
  2610.     Call PropBag.WriteProperty("ColHeader", bColHeader, True)
  2611.     Call PropBag.WriteProperty("RowHeader", bRowHeader, True)
  2612.     Call PropBag.WriteProperty("SelectionMode", iSelectionMode, 0)
  2613.     Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
  2614.     Call PropBag.WriteProperty("Font", fFont, Ambient.Font)
  2615.     Call PropBag.WriteProperty("FontFixed", fFontFixed, Ambient.Font)
  2616.     Call PropBag.WriteProperty("BackColorBkg", lBackColorBkg, COLOR_DARKGREY)
  2617.     Call PropBag.WriteProperty("AllowUserResizing", bAllowUserResizing, True)
  2618.     Call PropBag.WriteProperty("FormatString", sFormatString, "")
  2619.     Call PropBag.WriteProperty("AutoNewRow", bAutoNewRow, False)
  2620.     Call PropBag.WriteProperty("ListBoxRows", m_ListBoxRows, 6)
  2621.     
  2622.     If Not UserControl.Ambient.UserMode Then
  2623.       Call PropBag.WriteProperty("Count", LookupValues.Count, 0)
  2624.       For Index = 1 To LookupValues.Count
  2625.         Call PropBag.WriteProperty("Column" & Index, LookupValues(Index).Column)
  2626.         Call PropBag.WriteProperty("Value" & Index, LookupValues(Index).Value)
  2627.       Next
  2628.     End If
  2629. End Sub
  2630.  
  2631. Private Sub InitializeCols(lTopCol&)
  2632.     Dim lStartCol As Long, lStartRow As Long
  2633.     Dim fntTemp As Font
  2634.     
  2635.     'Set up the defaults for cells
  2636.     ReDim Preserve lColWidth(0 To lTopCol&) As Integer
  2637.     ReDim Preserve lColAlign(0 To lTopCol&) As Integer
  2638.     ReDim Preserve bColEdit(0 To lTopCol&) As Boolean
  2639.     ReDim Preserve lColMask(0 To lTopCol&) As Integer
  2640.     If lCols& = 0 Then
  2641.         lStartCol& = 0
  2642.     Else
  2643.         lStartCol& = lCols& + 1
  2644.     End If
  2645.     
  2646.     If lRows& = 0 Then ReDim Preserve lRowHeight(0 To 1) As Integer
  2647.     lStartRow& = 0
  2648.     
  2649.     lTopRowMember& = lRows&
  2650.     If lTopRowMember& = 0 Then lTopRowMember& = 1
  2651.     lTopColMember& = lTopCol&
  2652.     If lTopColMember& = 0 Then lTopColMember& = 1
  2653.     Cells.Cols = lTopColMember&
  2654.     
  2655.     lColCount& = 0
  2656.     lRowCount& = 0
  2657.     iCharscount% = 1
  2658.     For lMyCol& = lStartCol& To lTopCol&
  2659.         If lMyCol& = 0 Then
  2660.             lColWidth(lMyCol&) = 32
  2661.         Else
  2662.             lColWidth(lMyCol&) = 64
  2663.         End If
  2664.         lColAlign(lMyCol&) = ALIGN_LEFT         'kdq091498      added for easier FormatString implementation
  2665.         bColEdit(lMyCol&) = True                      'cell editing TRUE
  2666.         lColMask(lMyCol&) = 0                           'no mask
  2667.         For lMyRow& = lStartRow& To lRows&
  2668.             lRowHeight(lMyRow&) = 15
  2669.             If lMyRow& > 0 And lMyCol& > 0 Then
  2670.                 Cells.Style(lMyCol&, lMyRow&) = STYLE_EDIT
  2671.             ElseIf lMyRow& = 0 Then
  2672.                 If lMyCol& > 0 Then
  2673.                     lColCount& = lColCount& + 1
  2674.                     iChar% = 64 + lColCount&
  2675.                     sChar$ = Chr$(iChar%)
  2676.                     If sChar$ > "Z" Then
  2677.                         lColCount& = 1
  2678.                         iCharscount% = iCharscount% + 1
  2679.                         iChar% = 65
  2680.                     End If
  2681.                     'Cells.Text(lMyCol&, lMyRow&) = String$(iCharscount%, iChar%)
  2682.                 End If
  2683.                 'Cells.TextAlign(lMyCol&, lMyRow&) = ALIGN_LEFT
  2684.                 Cells.TextAlignVertical(lMyCol&, lMyRow&) = ALIGNV_CENTER
  2685.                 'Set fntTemp = Cells.Font(lMyCol&, lMyRow&)
  2686.                 'fntTemp.Bold = True
  2687.                 'Set Cells.Font(lMyCol&, lMyRow&).Bold = fntTemp
  2688.                 Cells.Style(lMyCol&, lMyRow&) = STYLE_BUTTON
  2689.             ElseIf lMyCol& = 0 Then
  2690.                 'Cells.TextAlign(lMyCol&, lMyRow&) = ALIGN_LEFT
  2691.                 Cells.TextAlignVertical(lMyCol&, lMyRow&) = ALIGNV_CENTER
  2692.                 'Set fntTemp = Cells.Font(lMyCol&, lMyRow&)
  2693.                 'fntTemp.Bold = True
  2694.                 'Set Cells.Font(lMyCol&, lMyRow&).Bold = fntTemp
  2695.                 If lMyRow& > 0 Then
  2696.                     lRowCount& = lRowCount& + 1
  2697.                     'Cells.Text(lMyCol&, lMyRow&) = CStr(lRowCount&)
  2698.                     Cells.Style(lMyCol&, lMyRow&) = STYLE_BUTTON
  2699.                     Cells.Value(lMyCol&, lMyRow&) = False
  2700.                 End If
  2701.             End If
  2702.         Next
  2703.     Next
  2704. End Sub
  2705.  
  2706. Private Sub InitializeRows(lTopRow&)
  2707.     Dim lStartCol As Long, lStartRow As Long
  2708.     
  2709.     'Set up the defaults for cells
  2710.     If lCols& = 0 Then
  2711.       ReDim Preserve lColWidth(0 To 1) As Integer
  2712.       ReDim Preserve lColAlign(0 To 1) As Integer
  2713.       ReDim Preserve bColEdit(0 To 1) As Boolean
  2714.       ReDim Preserve lColMask(0 To 1) As Integer
  2715.     End If
  2716.     lStartCol& = 0
  2717.     
  2718.     ReDim Preserve lRowHeight(0 To lTopRow&) As Integer
  2719.     If lRows& = 0 Then
  2720.         lStartRow& = 0
  2721.     Else
  2722.         lStartRow& = lRows& + 1
  2723.     End If
  2724.     
  2725.     lTopRowMember& = lTopRow&
  2726.     If lTopRowMember& = 0 Then lTopRowMember& = 1
  2727.     lTopColMember& = lCols&
  2728.     If lTopColMember& = 0 Then lTopColMember& = 1
  2729.     Cells.Rows = lTopRowMember&
  2730.     
  2731.     lColCount& = 0
  2732.     lRowCount& = 0
  2733.     iCharscount% = 1
  2734.     For lMyCol& = lStartCol& To lCols&
  2735.         'If lMyCol& = 0 Then
  2736.         '    lColWidth(lMyCol&) = 32
  2737.         'Else
  2738.         '    lColWidth(lMyCol&) = 64
  2739.         'End If
  2740.         'lColAlign(lMyCol&) = ALIGN_LEFT         'kdq091498      added for easier FormatString implementation
  2741.         For lMyRow& = lStartRow& To lTopRow&
  2742.             lRowHeight(lMyRow&) = 15
  2743.             If lMyRow& > 0 And lMyCol& > 0 Then
  2744.                 'Cells.Style(lMyCol&, lMyRow&) = STYLE_NORMAL
  2745.                 Cells.Style(lMyCol&, lMyRow&) = STYLE_EDIT
  2746.             ElseIf lMyRow& = 0 Then
  2747.                 If lMyCol& > 0 Then
  2748.                     lColCount& = lColCount& + 1
  2749.                     iChar% = 64 + lColCount&
  2750.                     sChar$ = Chr$(iChar%)
  2751.                     If sChar$ > "Z" Then
  2752.                         lColCount& = 1
  2753.                         iCharscount% = iCharscount% + 1
  2754.                         iChar% = 65
  2755.                     End If
  2756.                     'Cells.Text(lMyCol&, lMyRow&) = String$(iCharscount%, iChar%)
  2757.                 End If
  2758.                 'Cells.TextAlign(lMyCol&, lMyRow&) = ALIGN_LEFT
  2759.                 Cells.TextAlignVertical(lMyCol&, lMyRow&) = ALIGNV_CENTER
  2760.                 'Cells.Font(lMyCol&, lMyRow&).Bold = True
  2761.                 Cells.Style(lMyCol&, lMyRow&) = STYLE_BUTTON
  2762.             ElseIf lMyCol& = 0 Then
  2763.                 'Cells.TextAlign(lMyCol&, lMyRow&) = ALIGN_LEFT
  2764.                 Cells.TextAlignVertical(lMyCol&, lMyRow&) = ALIGNV_CENTER
  2765.                 'Cells.Font(lMyCol&, lMyRow&).Bold = True
  2766.                 If lMyRow& > 0 Then
  2767.                     lRowCount& = lRowCount& + 1
  2768.                     'Cells.Text(lMyCol&, lMyRow&) = CStr(lRowCount&)
  2769.                     Cells.Style(lMyCol&, lMyRow&) = STYLE_BUTTON
  2770.                     Cells.Value(lMyCol&, lMyRow&) = False
  2771.                 End If
  2772.             End If
  2773.         Next
  2774.     Next
  2775. End Sub
  2776.  
  2777. Private Sub HideEdit()
  2778.     Dim lX As Long, lY As Long
  2779.     
  2780.     If bDAO Then
  2781.         If lRow > 0 And lCol > 0 Then
  2782.             m_Recordset.AbsolutePosition = lRow - 1
  2783.             m_Recordset.Edit
  2784.             m_Recordset(lCol - 1) = Left$(txtEdit, m_Recordset.Fields(lCol - 1).Size)
  2785.             m_Recordset.Update
  2786.         Else
  2787.             Cells.Text(lCol, lRow) = txtEdit
  2788.         End If
  2789.     ElseIf bRDO Then
  2790.         Cells.Text(lCol, lRow) = txtEdit
  2791.     Else
  2792.         If Not ColHasLookup(lCol) Then Cells.Text(lCol, lRow) = txtEdit
  2793.     End If
  2794.     If txtEdit.Visible Then
  2795.         txtEdit.Visible = False
  2796.         'raiseevent leavecell
  2797.         RaiseEvent AfterEdit(lRow, lCol, Text)
  2798.     End If
  2799.     txtEdit.ZOrder 1
  2800.     bEditMode = False
  2801.     lMyColWidth& = lColWidth(lCol&)
  2802.     lMyRowHeight& = lRowHeight(lRow&)
  2803.     GetCellCoordinates lRow, lCol, lX, lY
  2804.     DrawCell lRow, lCol, lX&, lY&, lMyColWidth&, lMyRowHeight&
  2805.     DrawGridBorder
  2806. End Sub
  2807.  
  2808. Public Property Get RowHeight(lThisRow As Long) As Long
  2809. Attribute RowHeight.VB_Description = "Sets/gets the height of a row"
  2810. Attribute RowHeight.VB_MemberFlags = "400"
  2811.     RowHeight = lRowHeight(lThisRow)
  2812. End Property
  2813.  
  2814. Public Property Let RowHeight(lThisRow As Long, ByVal lNewValue As Long)
  2815.     lRowHeight(lThisRow) = lNewValue
  2816.     Refresh
  2817. End Property
  2818.  
  2819. Public Property Get ColWidth(lThisCol As Long) As Long
  2820. Attribute ColWidth.VB_Description = "Gets/sets width of a column"
  2821. Attribute ColWidth.VB_MemberFlags = "400"
  2822.     ColWidth = lColWidth(lThisCol)
  2823. End Property
  2824.  
  2825. Public Property Let ColWidth(lThisCol As Long, ByVal lNewValue As Long)
  2826.     lColWidth(lThisCol) = lNewValue
  2827.     Refresh
  2828. End Property
  2829.  
  2830. Public Property Get ColAlign(lThisCol As Long) As Long
  2831. Attribute ColAlign.VB_Description = "Gets/sets the text alignment for a column"
  2832.     ColAlign(lThisCol) = lColAlign(lThisCol)
  2833. End Property
  2834.  
  2835. Public Property Let ColAlign(lThisCol As Long, ByVal lNewValue As Long)
  2836.     If lNewValue = ALIGN_LEFT Or lNewValue = ALIGN_CENTER Or lNewValue = ALIGN_RIGHT Then
  2837.         lColAlign(lThisCol) = lNewValue
  2838.         Refresh
  2839.     End If
  2840. End Property
  2841.  
  2842. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  2843. 'MappingInfo=UserControl,UserControl,-1,BorderStyle
  2844. Public Property Get BorderStyle() As axgridBorderStyleEnum
  2845. Attribute BorderStyle.VB_Description = "Returns/sets the border style for an object."
  2846.     BorderStyle = iBorderStyle
  2847. End Property
  2848.  
  2849. Public Property Let BorderStyle(ByVal New_BorderStyle As axgridBorderStyleEnum)
  2850.     If Not (iBorderStyle = New_BorderStyle) Then
  2851.         iBorderStyle = New_BorderStyle
  2852.         UserControl.Cls
  2853.         UserControl_Paint
  2854.         PropertyChanged "BorderStyle"
  2855.     End If
  2856. End Property
  2857.  
  2858. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
  2859. 'MappingInfo=UserControl,UserControl,-1,MousePointer
  2860. Public Property Get MousePointer() As MousePointerConstants
  2861. Attribute MousePointer.VB_Description = "Returns/sets the type of mouse pointer displayed when over part of an object."
  2862.     MousePointer = UserControl.MousePointer
  2863. End Property
  2864.  
  2865. Public Property Let MousePointer(ByVal New_MousePointer As MousePointerConstants)
  2866.     UserControl.MousePointer() = New_MousePointer
  2867.     PropertyChanged "MousePointer"
  2868. End Property
  2869.  
  2870. Public Property Get Recordset() As Variant
  2871. Attribute Recordset.VB_MemberFlags = "40"
  2872.     Recordset = m_Recordset
  2873. End Property
  2874.  
  2875. Public Property Set Recordset(ByVal New_Recordset As Variant)
  2876.     Set m_Recordset = New_Recordset
  2877.     PropertyChanged "Recordset"
  2878.     
  2879.     'Now set the grid up to get its data from the Recordset
  2880.     bDAO = True
  2881.     bRDO = False
  2882.     
  2883.     m_Recordset.MoveLast
  2884.     Rows = m_Recordset.AbsolutePosition + 1
  2885.     
  2886.     SetupColumns
  2887. End Property
  2888.  
  2889. Private Sub SetupColumns()
  2890.     Dim lIndex As Long
  2891.     
  2892.     If bDAO Then
  2893.         Cols = m_Recordset.Fields.Count
  2894.         For lIndex& = 0 To m_Recordset.Fields.Count - 1
  2895.             Cells.Text(lIndex& + 1, 0) = m_Recordset.Fields(lIndex&).Name
  2896.             
  2897.             'Now set the column width
  2898.             Select Case m_Recordset.Fields(lIndex&).Type
  2899.             Case dbText
  2900.                 ColWidth(lIndex& + 1) = UserControl.TextWidth(String$(m_Recordset.Fields(lIndex&).Size, "N"))
  2901.             End Select
  2902.         Next
  2903.     Else
  2904.         'It's RDO, so use the rdoResultset
  2905.     End If
  2906. End Sub
  2907.  
  2908. Public Property Get AllowSelection() As Boolean
  2909. Attribute AllowSelection.VB_Description = "Determines if user can select multiple cells"
  2910.   AllowSelection = bAllowSelection
  2911. End Property
  2912.  
  2913. Property Let AllowSelection(bNewVal As Boolean)
  2914.   bAllowSelection = bNewVal
  2915.   PropertyChanged "AllowSelection"
  2916. End Property
  2917.  
  2918. Public Property Get BackColor() As OLE_COLOR
  2919. Attribute BackColor.VB_Description = "Sets/gets background color of the grid"
  2920.     BackColor = lBackColor
  2921. End Property
  2922.  
  2923. Public Property Let BackColor(ByVal lNewValue As OLE_COLOR)
  2924.       lBackColor = lNewValue
  2925.       InitializeRows lRows
  2926.       Refresh
  2927.       PropertyChanged "BackColor"
  2928. End Property
  2929.  
  2930. Public Property Get BackColorFixed() As OLE_COLOR
  2931. Attribute BackColorFixed.VB_Description = "Sets/gets the background color of the row and column headers"
  2932.     BackColorFixed = lBackColorFixed
  2933. End Property
  2934.  
  2935. Public Property Let BackColorFixed(ByVal lNewValue As OLE_COLOR)
  2936.       lBackColorFixed = lNewValue
  2937.       Refresh
  2938.       PropertyChanged "BackColorFixed"
  2939. End Property
  2940.  
  2941. Public Property Get ForeColor() As OLE_COLOR
  2942. Attribute ForeColor.VB_Description = "Gets/sets foreground color used for text in grid"
  2943.     ForeColor = lForeColor
  2944. End Property
  2945.  
  2946. Public Property Let ForeColor(ByVal lNewValue As OLE_COLOR)
  2947.       lForeColor = lNewValue
  2948.       PropertyChanged "ForeColor"
  2949. End Property
  2950.  
  2951. Public Property Get ForeColorFixed() As OLE_COLOR
  2952. Attribute ForeColorFixed.VB_Description = "Gets/sets color used in text for row and column headers"
  2953.     ForeColorFixed = lForeColorFixed
  2954. End Property
  2955.  
  2956. Public Property Let ForeColorFixed(ByVal lNewValue As OLE_COLOR)
  2957.       lForeColorFixed = lNewValue
  2958.       Refresh
  2959.       PropertyChanged "ForeColorFixed"
  2960. End Property
  2961.  
  2962. Public Property Get FixedStyle() As FixedStyles
  2963. Attribute FixedStyle.VB_Description = "Determines style of row and column headers"
  2964.     FixedStyle = iFixedStyle
  2965. End Property
  2966.  
  2967. Public Property Let FixedStyle(ByVal iNew_Value As FixedStyles)
  2968.     If Not (iFixedStyle = iNew_Value) Then
  2969.         iFixedStyle = iNew_Value
  2970.         Refresh
  2971.         PropertyChanged "FixedStyle"
  2972.     End If
  2973. End Property
  2974.  
  2975. Public Property Get SelectionMode() As SelectModes
  2976.   SelectionMode = iSelectionMode
  2977. End Property
  2978.  
  2979. Public Property Let SelectionMode(ByVal iNew_Value As SelectModes)
  2980.   iSelectionMode = iNew_Value
  2981.   PropertyChanged "SelectionMode"
  2982. End Property
  2983.  
  2984. Public Property Get Enabled() As Boolean
  2985.   Enabled = UserControl.Enabled
  2986. End Property
  2987.  
  2988. Property Let Enabled(bNewVal As Boolean)
  2989.   UserControl.Enabled = bNewVal
  2990.   PropertyChanged "Enabled"
  2991. End Property
  2992.  
  2993. Public Property Get Font() As Font
  2994. Attribute Font.VB_Description = "Gets/sets font used for text in grid"
  2995.     Set Font = fFont
  2996. End Property
  2997.  
  2998. Property Set Font(New_Font As Font)
  2999.         Set fFont = New_Font
  3000.         Refresh
  3001.         PropertyChanged "Font"
  3002. End Property
  3003.  
  3004. Public Property Get FontFixed() As Font
  3005. Attribute FontFixed.VB_Description = "Gets/sets font used in text for row and column headers"
  3006.     Set FontFixed = fFontFixed
  3007. End Property
  3008.  
  3009. Property Set FontFixed(New_Font As Font)
  3010.         Set fFontFixed = New_Font
  3011.         Refresh
  3012.         PropertyChanged "FontFixed"
  3013. End Property
  3014.  
  3015. Sub ShowAbout()
  3016. Attribute ShowAbout.VB_Description = "Show the about box"
  3017. Attribute ShowAbout.VB_UserMemId = -552
  3018.   frmAbout.Show vbModal
  3019. End Sub
  3020.  
  3021. Public Property Get BackColorBkg() As OLE_COLOR
  3022. Attribute BackColorBkg.VB_Description = "Sets/gets the background color of the usercontrol (behind the grid)"
  3023.     BackColorBkg = lBackColorBkg
  3024. End Property
  3025.  
  3026. Public Property Let BackColorBkg(ByVal lNewValue As OLE_COLOR)
  3027.       lBackColorBkg = lNewValue
  3028.       Refresh
  3029.       PropertyChanged "BackColorBkg"
  3030. End Property
  3031.  
  3032. Public Property Get AllowUserResizing() As Boolean
  3033. Attribute AllowUserResizing.VB_Description = "Determines if user can resize columns"
  3034.   AllowUserResizing = bAllowUserResizing
  3035. End Property
  3036.  
  3037. Property Let AllowUserResizing(bNewVal As Boolean)
  3038.   bAllowUserResizing = bNewVal
  3039.   PropertyChanged "AllowUserResizing"
  3040. End Property
  3041.  
  3042. Public Property Get FormatString() As String
  3043. Attribute FormatString.VB_Description = "Sets a format string that sets up a the control's column widths, alignments, and fixed row and column text\r\n"
  3044.   FormatString = sFormatString
  3045. End Property
  3046.  
  3047. Property Let FormatString(sNewVal As String)
  3048.   Dim cnt As Long
  3049.   sFormatString = sNewVal
  3050.   ClearAllLookups
  3051.   UpdateHeader
  3052.   Refresh
  3053.   PropertyChanged "FormatString"
  3054. End Property
  3055.  
  3056. Private Sub UpdateHeader()
  3057.   Dim ColCnt As Long, Char As String, CharStr As String, cnt As Long
  3058.   Dim AlignStr As String, lAlign As Long, RowText As Boolean, RowCnt As Long
  3059.   
  3060.   RowText = False
  3061.   ColCnt = 1: RowCnt = 1
  3062.   CharStr = ""
  3063.   For cnt = 1 To Len(sFormatString)
  3064.     Char = Mid(sFormatString, cnt, 1)
  3065.     
  3066.     If Char = "|" Or Char = ";" Then
  3067.       If CharStr > "" And Not RowText Then
  3068.             If ColCnt > Cols Then Cols = ColCnt
  3069.             AlignStr = ""
  3070.             If InStr("<^>", Left(CharStr, 1)) Then
  3071.               AlignStr = Left(CharStr, 1)
  3072.               CharStr = Right(CharStr, Len(CharStr) - 1)
  3073.             End If
  3074.             Select Case AlignStr
  3075.             Case "<"
  3076.                 lAlign = ALIGN_LEFT
  3077.             Case "^"
  3078.                 lAlign = ALIGN_CENTER
  3079.             Case ">"
  3080.                 lAlign = ALIGN_RIGHT
  3081.             Case Else
  3082.                 lAlign = ALIGN_LEFT
  3083.             End Select
  3084.             
  3085.             lColAlign(ColCnt) = lAlign
  3086.             lColWidth(ColCnt) = TextWidth(CharStr) + 5
  3087.             Cells.Text(ColCnt, 0) = RTrim(CharStr)
  3088.             ColCnt = ColCnt + 1
  3089.       
  3090.       ElseIf CharStr > "" And RowText Then
  3091.             ColCnt = 0
  3092.             If RowCnt > Rows Then Rows = RowCnt
  3093.             If lColWidth(ColCnt) < TextWidth(CharStr) + 5 Then
  3094.                 lColWidth(ColCnt) = TextWidth(CharStr) + 5
  3095.             End If
  3096.             Cells.Text(ColCnt, RowCnt) = RTrim(CharStr)
  3097.             RowCnt = RowCnt + 1
  3098.       Else
  3099.             Cells.Text(ColCnt, 0) = ""
  3100.             lColWidth(ColCnt) = 64
  3101.           ColCnt = ColCnt + 1
  3102.       End If
  3103.       CharStr = ""
  3104.       If Char = ";" Then RowText = True
  3105.     
  3106.     Else
  3107.       CharStr = CharStr + Char
  3108.     End If
  3109.   Next
  3110.   
  3111.       If CharStr > "" And Not RowText Then
  3112.             If ColCnt > Cols Then Cols = ColCnt
  3113.             AlignStr = ""
  3114.             If InStr("<^>", Left(CharStr, 1)) Then
  3115.               AlignStr = Left(CharStr, 1)
  3116.               CharStr = Right(CharStr, Len(CharStr) - 1)
  3117.             End If
  3118.             Select Case AlignStr
  3119.             Case "<"
  3120.                 lAlign = ALIGN_LEFT
  3121.             Case "^"
  3122.                 lAlign = ALIGN_CENTER
  3123.             Case ">"
  3124.                 lAlign = ALIGN_RIGHT
  3125.             Case Else
  3126.                 lAlign = ALIGN_LEFT
  3127.             End Select
  3128.             
  3129.             lColAlign(ColCnt) = lAlign
  3130.             lColWidth(ColCnt) = TextWidth(CharStr) + 5
  3131.             Cells.Text(ColCnt, 0) = RTrim(CharStr)
  3132.             ColCnt = ColCnt + 1
  3133.   If ColCnt + 1 <= Cols Then
  3134.     For cnt = ColCnt + 1 To Cols
  3135.       Cells.Text(cnt, 0) = ""
  3136.       lColWidth(cnt) = 64
  3137.     Next
  3138.   End If
  3139.       
  3140.       ElseIf CharStr > "" And RowText Then
  3141.             ColCnt = 0
  3142.             If RowCnt > Rows Then Rows = RowCnt
  3143.             If lColWidth(ColCnt) < TextWidth(CharStr) + 5 Then
  3144.                 lColWidth(ColCnt) = TextWidth(CharStr) + 5
  3145.             End If
  3146.             Cells.Text(ColCnt, RowCnt) = RTrim(CharStr)
  3147.   If RowCnt + 1 <= Rows Then
  3148.     For cnt = RowCnt + 1 To Rows
  3149.       Cells.Text(0, Rows) = ""
  3150.       lColWidth(0) = 64
  3151.     Next
  3152.   End If
  3153.       End If
  3154.   
  3155. End Sub
  3156. Public Sub AutoSetup(NRows As Variant, NCols As Variant, vRowHeader As Boolean, vColHeader As Boolean, vFormatString As Variant)
  3157. Attribute AutoSetup.VB_Description = "Automatically setup the grid by passing rows, cols, and a format string"
  3158. Dim cnt As Integer
  3159. ' Always (re)set to zero to avoid errors when fixedrows >= rows
  3160.   bRedraw = False
  3161.  
  3162.   Rows = NRows
  3163.   Cols = NCols
  3164.   
  3165.   RowHeader = vRowHeader
  3166.   ColHeader = vColHeader
  3167.   
  3168.   sFormatString = vFormatString
  3169.   ClearAllLookups
  3170.   UpdateHeader
  3171.   bRedraw = True
  3172.   Refresh
  3173.   
  3174. End Sub
  3175.  
  3176. Private Sub SetSizers()
  3177.     If bAllowUserResizing Then
  3178.         Do While hSizers.Count
  3179.             hSizers.Remove 1
  3180.         Loop
  3181.         
  3182.         Do While vSizers.Count
  3183.             vSizers.Remove 1
  3184.         Loop
  3185.         
  3186.         lScaleHeight = UserControl.ScaleHeight
  3187.         lScaleWidth = UserControl.ScaleWidth
  3188.         
  3189.         If bRowHeader Then
  3190.             lCumulative& = ColWidth(0)
  3191.         hSizers.Add lCumulative&
  3192.         Else
  3193.             lCumulative& = 0
  3194.         End If
  3195.         For lColCount& = lLeftCol To lCols
  3196.             lCumulative& = lCumulative& + ColWidth(lColCount&) + 1
  3197.             If lCumulative& > lScaleWidth Then
  3198.                 Exit For
  3199.             Else
  3200.                 hSizers.Add lCumulative&
  3201.             End If
  3202.         Next
  3203.         
  3204. '        If bRowHeader Then
  3205. '            lCumulative& = RowHeight(0) + 1
  3206. '        Else
  3207. '            lCumulative& = 0
  3208. '        End If
  3209. '        vSizers.Add lCumulative&
  3210. '        For lRowCount& = lTopRow To lRows
  3211. '            lCumulative& = lCumulative& + RowHeight(lRowCount&) + 1
  3212. '            If lCumulative& > lScaleHeight Then
  3213. '                Exit For
  3214. '            Else
  3215. '                vSizers.Add lCumulative&
  3216. '            End If
  3217. '        Next
  3218.     End If
  3219. End Sub
  3220.  
  3221. Private Sub GridEdit(KeyAscii As Integer)
  3222.    Dim CancelEdit As Boolean
  3223.    Dim x As Integer
  3224.    Dim strX As String
  3225.    Dim bFoundStart As Boolean
  3226.    Dim intStart
  3227.    Dim ListHeight As Integer, ListRows As Integer
  3228.    Dim cellX As Long, cellY As Long
  3229.    
  3230.    CancelEdit = False
  3231.    
  3232.    RaiseEvent BeforeEdit(lRow, lCol, CancelEdit)
  3233.    If Not CancelEdit Then
  3234. '    If bEditMode = False And Cells.Style(lCol, lRow) = STYLE_EDIT Then
  3235.     If bEditMode = False And bColEdit(lCol) Then
  3236.         HilightCell lRow, lCol
  3237.             
  3238.         If lRow = lRows And RowEmpty(lRow) And bAutoNewRow Then
  3239.             'add row
  3240.             bCancel = False
  3241.             RaiseEvent BeforeAddRow(bCancel)
  3242.             If Not bCancel Then
  3243.                 Rows = Rows + 1
  3244.                 RaiseEvent AfterAddRow(Rows)
  3245.             End If
  3246.         End If
  3247.  
  3248.         bEditMode = True
  3249.         
  3250.        If ColHasLookup(lCol) Then
  3251.             If Not List1.Visible Then
  3252.                 FillCombo (lCol)
  3253.                 List1.FontName = picGrid.FontName
  3254.                 List1.FontSize = picGrid.FontSize
  3255.                 
  3256.                 'position the combo box
  3257.                 GetCellCoordinates lRow, lCol, cellX, cellY
  3258.                 List1.Left = cellX + 2
  3259.                 List1.Top = cellY + RowHeight(lRow) + 2
  3260.                 List1.Width = ColWidth(lCol)         '<-- Need to check for scrollbar
  3261.                 
  3262.                 ListRows = (picGrid.Height - List1.Top - RowHeight(lRow)) / RowHeight(lRow)
  3263.                 If ListRows > ListBoxRows Then ListRows = ListBoxRows
  3264.                 'ListRows = ListBoxRows
  3265.                 List1.Height = RowHeight(lRow) * (ListRows)   '       in the grid!
  3266.                 
  3267.                 List1.ZOrder
  3268.                 List1.Visible = True
  3269.                 List1.SetFocus
  3270.                 strX = Chr(KeyAscii)
  3271.                 bFoundStart = False
  3272.                 On Error Resume Next
  3273.                     For x = 0 To List1.ListCount - 1
  3274.                         If UCase(Left(List1.List(x), Len(strX))) = UCase(strX) Then
  3275.                             List1.Selected(x) = True
  3276.                             Exit For
  3277.                         End If
  3278.                     Next
  3279.                 On Error GoTo 0
  3280.             Else
  3281.                 'need to hide list
  3282.                 List1.Visible = False
  3283.                 flxGrid.SetFocus
  3284.             End If
  3285.        
  3286.        Else
  3287.         
  3288.         'RaiseEvent EnterCell
  3289.         'Get the text for this cell
  3290.         If bDAO Then
  3291.             If lRow > 0 And lCol > 0 Then
  3292.                 m_Recordset.AbsolutePosition = lRow - 1
  3293.                 txtEdit = m_Recordset(lCol - 1) & ""
  3294.             Else
  3295.                 txtEdit = Cells.Text(lCol, lRow)
  3296.             End If
  3297.         ElseIf bRDO Then
  3298.             
  3299.         Else
  3300.             txtEdit = Cells.Text(lCol, lRow)
  3301.         End If
  3302.         
  3303.         txtEdit.SelStart = Len(txtEdit)
  3304.         txtEdit.SelLength = 0
  3305.         'Set txtEdit.Font = Cells.Font(lCol, lRow)
  3306.         txtEdit.BackColor = vbWhite             'Cells.BackColor(lCol, lRow)
  3307.         txtEdit.ForeColor = vbBlack             'Cells.ForeColor(lCol, lRow)
  3308.         txtEdit.Visible = True
  3309.         txtEdit.ZOrder
  3310.         txtEdit.SetFocus
  3311.         End If
  3312.     End If
  3313.    
  3314.    End If
  3315. End Sub
  3316.  
  3317. Public Property Get AutoNewRow() As Boolean
  3318. Attribute AutoNewRow.VB_Description = "Determines if editing a cell on the last row automatically creates a new row"
  3319.     AutoNewRow = bAutoNewRow
  3320. End Property
  3321.  
  3322. Public Property Let AutoNewRow(ByVal New_Value As Boolean)
  3323.     bAutoNewRow = New_Value
  3324.     PropertyChanged "AutoNewRow"
  3325. End Property
  3326.  
  3327. Public Function RowEmpty(ByVal iRow As Long)
  3328. Attribute RowEmpty.VB_Description = "Used to determine if a row is empty, meaning it contains no text in any of the columns for that row. Returns a boolean expression\r\n"
  3329.     Dim a As Long
  3330.     Dim bRowEmpty As Boolean
  3331.     
  3332.     bRowEmpty = True
  3333.     
  3334.     For a = 1 To lCols
  3335.         If Len(Trim(TextMatrix(iRow, a))) > 0 Then
  3336.             bRowEmpty = False
  3337.             Exit For
  3338.         End If
  3339.     Next
  3340.     
  3341.     RowEmpty = bRowEmpty
  3342. End Function
  3343.  
  3344. Private Sub ShowLookup()
  3345.     Dim x As Long, y As Long
  3346.     GetCellCoordinates lRow, lCol, x, y
  3347.     If ColHasLookup(lCol) And lCol > 0 And lRow > 0 And lLeftCol <= lCol And lTopRow <= lRow And y + RowHeight(lRow) <= scrHorizontal.Top Then
  3348.           'GetCellCoordinates lRow, lCol, x, y
  3349.           cmdLookup.Move x + ColWidth(lCol) - cmdLookup.Width + 1, y + 3, cmdLookup.Width, RowHeight(lRow) - 2
  3350.           cmdLookup.Visible = True
  3351.     Else
  3352.           cmdLookup.Visible = False
  3353.     End If
  3354.  
  3355. End Sub
  3356.  
  3357. Public Sub AddLookup(iCol As Integer, Value As String)
  3358. Attribute AddLookup.VB_Description = "Add lookup list item for a specific column"
  3359.   Dim Item As New clsLookup
  3360.   Item.Column = iCol
  3361.   Item.Value = Value
  3362.   LookupValues.Add Item
  3363. End Sub
  3364.  
  3365. Public Sub RemoveLookup(iCol As Integer, Value As String)
  3366. Attribute RemoveLookup.VB_Description = "Remove a specific lookup list item for a column"
  3367.   Dim cnt As Integer
  3368.   For cnt = 1 To LookupValues.Count
  3369.     If LookupValues(cnt).Value = Value And LookupValues(cnt).Column = iCol Then
  3370.       LookupValues.Remove cnt
  3371.       Exit For
  3372.     End If
  3373.   Next
  3374. End Sub
  3375.  
  3376. Public Sub ClearLookup(iCol As Integer)
  3377. Attribute ClearLookup.VB_Description = "Remove lookup items for a specific column"
  3378.   Dim cnt As Integer
  3379.   For cnt = 1 To LookupValues.Count
  3380.     If LookupValues(cnt).Column = iCol Then
  3381.       LookupValues.Remove cnt
  3382.       cnt = 1
  3383.     End If
  3384.   Next
  3385. End Sub
  3386.  
  3387. Public Sub ClearAllLookups()
  3388. Attribute ClearAllLookups.VB_Description = "Remove all lookup items for all columns"
  3389.   Do Until LookupValues.Count = 0
  3390.     LookupValues.Remove 1
  3391.   Loop
  3392. End Sub
  3393.  
  3394. Public Function ColHasLookup(ByVal iCol As Integer) As Boolean
  3395. Attribute ColHasLookup.VB_Description = "Gets a value to determine if a column has lookup items"
  3396.   Dim cnt As Integer
  3397.   For cnt = 1 To LookupValues.Count
  3398.     If LookupValues(cnt).Column = iCol Then
  3399.       ColHasLookup = True
  3400.       Exit Function
  3401.     End If
  3402.   Next
  3403.   ColHasLookup = False
  3404. End Function
  3405.  
  3406. Private Sub FillCombo(iCol As Integer)
  3407.   Dim cnt As Integer
  3408.   List1.Clear
  3409.   For cnt = 1 To LookupValues.Count
  3410.     If LookupValues(cnt).Column = iCol Then
  3411.       List1.AddItem LookupValues(cnt).Value
  3412.     End If
  3413.   Next
  3414. End Sub
  3415.  
  3416. Public Property Get ListBoxRows() As Integer
  3417. Attribute ListBoxRows.VB_Description = "Returns or sets the default number of items to display in the dropdown listbox when a column has a dropdown"
  3418.     ListBoxRows = m_ListBoxRows
  3419. End Property
  3420.  
  3421. Public Property Let ListBoxRows(ByVal New_ListBoxRows As Integer)
  3422.     m_ListBoxRows = New_ListBoxRows
  3423.     PropertyChanged "ListBoxRows"
  3424. End Property
  3425.  
  3426. Public Property Get ColAllowEdit(ByVal iCol As Long) As Boolean
  3427. Attribute ColAllowEdit.VB_Description = "Determines if a column will allow editing"
  3428.     ColAllowEdit = bColEdit(iCol)
  3429. End Property
  3430.  
  3431. Public Property Let ColAllowEdit(ByVal iCol As Long, ByVal Value As Boolean)
  3432.     bColEdit(iCol) = Value
  3433.     PropertyChanged "ColAllowEdit"
  3434. End Property
  3435.  
  3436. Public Property Get ColMask(ByVal iCol As Long) As Integer
  3437. Attribute ColMask.VB_Description = "Gets/sets a value to determine what kind of mask will be used for a column"
  3438.     ColMask = lColMask(iCol)
  3439. End Property
  3440.  
  3441. Public Property Let ColMask(ByVal iCol As Long, ByVal Value As Integer)
  3442.     If Value >= 0 And Value <= 4 Then
  3443.       lColMask(iCol) = Value
  3444.     End If
  3445. End Property
  3446.  
  3447. Private Sub List1_LostFocus()
  3448.       bEditMode = False
  3449.       'Text = IIf(List1.ListIndex >= 0, List1.List(List1.ListIndex), Text)
  3450.       List1.Visible = False
  3451.       picGrid.SetFocus
  3452.       GetCellCoordinates lRow, lCol, x&, y&
  3453.       DrawCell lRow, lCol, x&, y&, ColWidth(lCol), RowHeight(lRow)
  3454.       DrawGridBorder
  3455.       HilightCell lRow, lCol
  3456.       'RaiseEvent AfterEdit(lRow, lCol, Text)
  3457. End Sub
  3458.  
  3459. Private Sub list1_DblClick()
  3460.     bEditMode = False
  3461.     Text = IIf(List1.ListIndex >= 0, List1.List(List1.ListIndex), Text)
  3462.     List1.Visible = False
  3463.     picGrid.SetFocus
  3464.     GetCellCoordinates lRow, lCol, x&, y&
  3465.     DrawCell lRow, lCol, x&, y&, ColWidth(lCol), RowHeight(lRow)
  3466.     DrawGridBorder
  3467.     HilightCell lRow, lCol
  3468.     RaiseEvent AfterEdit(lRow, lCol, Text)
  3469. End Sub
  3470.  
  3471. Private Sub list1_KeyDown(KeyCode As Integer, Shift As Integer)
  3472.     Select Case KeyCode
  3473.         Case vbKeyEscape
  3474.             bEditMode = False
  3475.             List1.Visible = False
  3476.         Case vbKeyReturn
  3477.             bEditMode = False
  3478.             Text = IIf(List1.ListIndex >= 0, List1.List(List1.ListIndex), Text)
  3479.             List1.Visible = False
  3480.             picGrid.SetFocus
  3481.             GetCellCoordinates lRow, lCol, x&, y&
  3482.             DrawCell lRow, lCol, x&, y&, ColWidth(lCol), RowHeight(lRow)
  3483.             DrawGridBorder
  3484.             HilightCell lRow, lCol
  3485.             RaiseEvent AfterEdit(lRow, lCol, Text)
  3486.     End Select
  3487. End Sub
  3488.  
  3489. Private Sub cmdLookup_Click()
  3490.      GridEdit Asc(" ")
  3491. End Sub
  3492.  
  3493.  
  3494. Private Function NumOnly(keyin As Integer) As Integer
  3495.   'only allow numeric characters in a textbox
  3496.   '  put in keypress event
  3497.   If (keyin < Asc("0") Or keyin > Asc("9")) And keyin <> 8 And keyin <> Asc("-") And keyin <> Asc(".") Then
  3498.     NumOnly = 0
  3499.   Else
  3500.     NumOnly = keyin
  3501.   End If
  3502. End Function
  3503.  
  3504. Private Function DateOnly(keyin As Integer) As Integer
  3505.   'only allow date characters in a text box
  3506.   '  put in KeyPress event
  3507.   If (keyin < Asc("0") Or keyin > Asc("9")) And keyin <> Asc("/") And keyin <> 8 Then
  3508.     DateOnly = 0
  3509.   Else
  3510.     DateOnly = keyin
  3511.   End If
  3512. End Function
  3513.  
  3514. Public Sub Remove(iRow As Integer)
  3515. Attribute Remove.VB_Description = "Remove the specified row from the grid"
  3516.   If Rows > 0 Then
  3517.       Cells.Remove iRow
  3518.       scrVertical.Max = lRows - 1
  3519.       InitializeRows lRows - 1
  3520.       lRows = lRows - 1
  3521.       If lRow > lRows Then lRow = lRows
  3522.       If lRow1 > lRows Then lRow1 = lRows
  3523.       If lRow2 > lRows Then lRow2 = lRows
  3524.       Refresh
  3525.   End If
  3526. End Sub
  3527.