ComponentOne True DBInput Pro 8.0
Tutorial 8 - Using TDBCalendar with TDBDate

In this tutorial, you will learn how to use the calendar control with the TDBDate control. The following sample overrides the built-in calendar with the calendar that will be set up on a second form.

  1. Start a new project.

  2. From the Visual Basic Project menu, select Components, then check the box labeled ComponentOne True DBCalendar 8.0. Click OK to add the TDBCalendar and control icon to the toolbox.

  3. Place a True DBDate control (tdbDate) on the form (Form1) as shown in the following figure.

  4. Add a new Form (Form2) to the project and place a True DBCalendar control (tdbCalendar) and command button (btnOk) on the form (Form2) as shown in the following figure.

  5. Using the Button property page of tdbDate, set the DropDown (calendar) Position to 1 – Outside Control, and Visible to True. For the Spin button, setthe Position to 0 – Inside Control, Increment to 1, and Visible to True.

  6. Using the Value property page of TDBDate, set the MinDate property to 100/1/1 and MaxDate to 2099/12/31.

  7. This code will set the date to the current date.

    Example Title
    Copy Code
    Private Sub Form_Load()
    
     
    
        ' Set date to today.
    
        TDBDate1.Value = Now    
    
    End Sub
    
  8. This code will set the dropdown calendar.

    Example Title
    Copy Code
    Private Sub TDBDate1_DropOpen(NoDefault As Boolean)
    
     
    
        ' Ignore the internal calendar.
    
        NoDefault = True
    
       
    
        ' Need to have the calendar reflect the current date.
    
        Form2. TDBCalendar1.Value = TDBDate1.Value
    
     
    
        ' The date range also needs to be the same.
    
        Form2. TDBCalendar1.MinDate = TDBDate1.MinDate
    
        Form2. TDBCalendar1.MaxDate = TDBDate1.MaxDate
    
       
    
        ' Show the custom calendar control.
    
        Form2.Show vbModal
    
    End Sub
    
  9. This code will verify the date entered.

    Example Title
    Copy Code
    Private Sub TDBDate1_InvalidValue(Restore As Boolean)
    
     
    
        ' By setting the Restore param to False, the previous value will not be restored, and the date will reset to Null.
    
        Restore = False
    
    End Sub
    
  10. When the OK button is clicked on Form2, the selected date will be applied back to the Date control. The code is as follows:

    Example Title
    Copy Code
    Private Sub btnOk_Click()
    
       
    
        ' Apply selected date back to control.
    
        Form1.TDBDate.Value = TDBCalendar1.Value
    
           
    
        ' Close form for [Esc] or [Cr] key.
    
        Unload Me
    
    End Sub
    
  11. When the ENTER or ESCAPE keys are pressed, this code will cause the focus to go back to Form1.

    Example Title
    Copy Code
    Private Sub TDBCalendar1_KeyDown(KeyCode As Integer, Shift As Integer)
    
     
    
        ' Process the [Esc] and [Cr] keys.
    
        If KeyCode = vbKeyEscape Or KeyCode = vbKeyReturn Then
    
           
    
            ' Apply selected date back to control.
    
            If KeyCode = vbKeyReturn Then
    
                Form1. TDBDate1.Value = TDBCalendar1.Value
    
            End If
    
       
    
            ' Close form for [Esc] or [Cr] key.
    
            Unload Me
    
        End If
    
    End Sub
    

Run the program and observe the following:

The built-in calendar for the TDBDate control was replaced by the TDBCalendar control.



This concludes Tutorial 8.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback