home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / LynxGrid_22207947122011.psc / BoundControls.frm < prev    next >
Text File  |  2010-11-11  |  8KB  |  264 lines

  1. VERSION 5.00
  2. Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomct2.ocx"
  3. Begin VB.Form frmBoundControls 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "LynxGrid Demo"
  6.    ClientHeight    =   6255
  7.    ClientLeft      =   4455
  8.    ClientTop       =   3600
  9.    ClientWidth     =   6600
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   6255
  14.    ScaleWidth      =   6600
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   1  'CenterOwner
  17.    Begin VB.Frame Frame1 
  18.       Caption         =   "Frame1"
  19.       Height          =   645
  20.       Left            =   4110
  21.       TabIndex        =   4
  22.       Top             =   5460
  23.       Visible         =   0   'False
  24.       Width           =   1755
  25.       Begin VB.TextBox txtName 
  26.          BackColor       =   &H00FFFF80&
  27.          BorderStyle     =   0  'None
  28.          Height          =   285
  29.          Left            =   0
  30.          TabIndex        =   5
  31.          Top             =   0
  32.          Visible         =   0   'False
  33.          Width           =   1155
  34.       End
  35.    End
  36.    Begin MSComCtl2.DTPicker dtpDOB 
  37.       Height          =   315
  38.       Left            =   3870
  39.       TabIndex        =   3
  40.       Top             =   3420
  41.       Visible         =   0   'False
  42.       Width           =   1185
  43.       _ExtentX        =   2090
  44.       _ExtentY        =   556
  45.       _Version        =   393216
  46.       Format          =   38338561
  47.       CurrentDate     =   38875
  48.    End
  49.    Begin VB.ComboBox cboJob 
  50.       Height          =   315
  51.       Left            =   2055
  52.       Style           =   2  'Dropdown List
  53.       TabIndex        =   2
  54.       Top             =   3150
  55.       Visible         =   0   'False
  56.       Width           =   1425
  57.    End
  58.    Begin LynxGridTest.LynxGrid LynxGrid 
  59.       Height          =   5175
  60.       Left            =   90
  61.       TabIndex        =   1
  62.       Top             =   450
  63.       Width           =   6360
  64.       _ExtentX        =   11218
  65.       _ExtentY        =   9128
  66.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  67.          Name            =   "MS Sans Serif"
  68.          Size            =   8.25
  69.          Charset         =   0
  70.          Weight          =   400
  71.          Underline       =   0   'False
  72.          Italic          =   0   'False
  73.          Strikethrough   =   0   'False
  74.       EndProperty
  75.       BeginProperty FontHeader {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  76.          Name            =   "MS Sans Serif"
  77.          Size            =   8.25
  78.          Charset         =   0
  79.          Weight          =   400
  80.          Underline       =   0   'False
  81.          Italic          =   0   'False
  82.          Strikethrough   =   0   'False
  83.       EndProperty
  84.       BackColorSel    =   12937777
  85.       ForeColorSel    =   16777215
  86.       CustomColorFrom =   16572875
  87.       CustomColorTo   =   14722429
  88.       GridColor       =   16367254
  89.       FocusRectMode   =   2
  90.       FocusRectColor  =   9895934
  91.       ColumnHeaderSmall=   0   'False
  92.       TotalsLineShow  =   0   'False
  93.       FocusRowHighlightKeepTextForecolor=   0   'False
  94.       ShowRowNumbers  =   -1  'True
  95.       ShowRowNumbersVary=   -1  'True
  96.       AllowRowResizing=   -1  'True
  97.       ColumnSort      =   -1  'True
  98.       Editable        =   -1  'True
  99.    End
  100.    Begin VB.Label Label1 
  101.       AutoSize        =   -1  'True
  102.       Caption         =   "Example of binding external Edit Controls"
  103.       BeginProperty Font 
  104.          Name            =   "MS Sans Serif"
  105.          Size            =   12
  106.          Charset         =   0
  107.          Weight          =   700
  108.          Underline       =   0   'False
  109.          Italic          =   0   'False
  110.          Strikethrough   =   0   'False
  111.       EndProperty
  112.       Height          =   300
  113.       Left            =   60
  114.       TabIndex        =   0
  115.       Top             =   60
  116.       Width           =   4965
  117.    End
  118. End
  119. Attribute VB_Name = "frmBoundControls"
  120. Attribute VB_GlobalNameSpace = False
  121. Attribute VB_Creatable = False
  122. Attribute VB_PredeclaredId = True
  123. Attribute VB_Exposed = False
  124. Option Explicit
  125.  
  126.  
  127. Private Sub cboJob_KeyDown(KeyCode As Integer, Shift As Integer)
  128.    If KeyCode = vbKeyReturn Then
  129.       LynxGrid.UpdateCell
  130.       KeyCode = 0
  131.    End If
  132. End Sub
  133.  
  134. Private Sub Form_Load()
  135.  
  136.    Call LoadDemoData
  137.  
  138. End Sub
  139.  
  140. Private Sub Form_Unload(Cancel As Integer)
  141.  
  142.    Set frmBoundControls = Nothing
  143.  
  144. End Sub
  145.  
  146. Private Sub LoadDemoData()
  147.  
  148.   Dim lCount      As Long
  149.   Dim strForeName As String
  150.  
  151.    With cboJob
  152.       For lCount = 0 To JobCount()
  153.          .AddItem GetJobName(lCount)
  154.       Next lCount
  155.    End With
  156.  
  157.    With LynxGrid
  158.       'Setting Redraw to False stops the Grid redrawing when Items/Cells are
  159.       'changed which makes adding data much faster (and stops application flickering)
  160.       .Redraw = False
  161.  
  162.       'EditTrigger defines which actions toggle Cell Edits. You can use multiple
  163.       'Triggers by using "Or" as below
  164.       .EditTrigger = lgEnterKey Or lgMouseDblClick
  165.  
  166.       'The height used for each Row (larger then the default)
  167.       .MinRowHeight = 315
  168.  
  169.       'Create the Columns
  170.       .AddColumn "Forename", 1500
  171.       .AddColumn "Surname", 1500
  172.       .AddColumn "Job Title", 1500
  173.       .AddColumn "DOB", 1250, , lgDate
  174.  
  175.       'Bind the external Controls to the Column
  176.       .BindControl 1, txtName  'Defaults to automatically changing Left, Top, Height & Width
  177.       .BindControl 2, cboJob ', lgBCLeft Or lgBCTop Or lgBCWidth Or lgBCHeight
  178.       .BindControl 3, dtpDOB, lgBCLeft Or lgBCTop Or lgBCWidth
  179.  
  180.       'Add some random data
  181.       For lCount = 0 To 15
  182.          
  183.          'Simple method to specify Gender!
  184.          If RandomInt(0, 1) = 0 Then
  185.             strForeName = GetForename(ntMale)
  186.          Else
  187.             strForeName = GetForename(ntFemale)
  188.          End If
  189.  
  190.          .AddItem strForeName & vbTab & _
  191.                   GetSurname() & vbTab & _
  192.                   GetJobName() & vbTab & _
  193.                   DateSerial(RandomInt(1930, 1990), RandomInt(1, 12), RandomInt(1, 28))
  194.                   
  195.       Next lCount
  196.  
  197.       'Tell the grid to Draw again!
  198.       .Redraw = True
  199.    End With
  200.  
  201. End Sub
  202.  
  203. Private Sub LynxGrid_Afteredit(ByVal Row As Long, ByVal Col As Long, NewValue As String, Cancel As Boolean)
  204.  
  205.    'This Event is fired before an Edit commits. Row & Col identify the Cell that
  206.    'will be updated. Setting Cancel=True will abort the Update
  207.  
  208.    'NewValue is used to get the data that will be used to update the Cell. For
  209.    'columns that are using the internal textbox this will be populated automatically
  210.  
  211.    Debug.Print "LynxGrid_AfterEdit"
  212.  
  213.    Select Case Col
  214.    Case 1 'Surname
  215.       NewValue = txtName.Text
  216.  
  217.    Case 2 'Job Title
  218.       NewValue = cboJob.Text
  219.  
  220.    Case 3 'DOB
  221.       NewValue = dtpDOB.Value
  222.  
  223.    End Select
  224.  
  225. End Sub
  226.  
  227. Private Sub LynxGrid_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
  228.  
  229.    'This Event is fired before an Edit begins. Row & Col identify the Cell that
  230.    'will be edited. Setting Cancel=True will abort the Edit
  231.  
  232.    'NOTE:
  233.    'If manual processing of the the Edit Control Size/Position is required then you can use the
  234.    'following:
  235.  
  236.    '.ColLeft(Col)     - The Left position of the Cell
  237.    '.ColWidth(Col)    - The Width of the Cell
  238.    '.RowTop(Row)      - The Top position of the Cell
  239.    '.RowHeightMin     - The Height of the Cell
  240.  
  241.    'The MoveControl setting on BindColumn defines what combination (if any) of Left, Top, Height & Width
  242.    'will be adjusted
  243.  
  244.    Debug.Print "LynxGrid_BeforeEdit"
  245.  
  246.    Select Case Col
  247.    Case 1 'Surname
  248.       txtName.Text = LynxGrid.CellText(Row, Col)
  249.  
  250.    Case 2 'Job Title
  251.       If Len(LynxGrid.CellText(Row, Col)) > 0 Then
  252.          cboJob.Text = LynxGrid.CellText(Row, Col)
  253.       Else
  254.          cboJob.ListIndex = -1
  255.       End If
  256.  
  257.    Case 3 'DOB
  258.       dtpDOB.Value = CDate(LynxGrid.CellText(Row, Col))
  259.  
  260.    End Select
  261.  
  262. End Sub
  263.  
  264.