ComponentOne Query 8.0
Tutorial 5 - Using the Sample User Control C1QueryUI

In this tutorial, you will use the C1QueryUI control, an ActiveX control created in Visual Basic. Full source code for this user control is provided in the USERCTL subdirectory. We encourage you to peruse the C1QueryUI code and experiment with your own modifications of the code; it will help you to learn more about useful C1Query features, especially about custom editing.

The user control code can serve as a sample showing how to use C1QueryFrame events for custom editing, BeforeEdit, ShowCustomEditor, EndEdit, HideCustomEditor, on a Visual Basic form. You don’t necessarily have to build a user control to use this functionality, it can be programmed on a form, if you need to use it in a single form in your application, or on a form-by-form basis. See the SAMPLES directory for a sample showing how to program custom editing in a Visual Basic form.

Attention: Tutorial 5 will not work right after you install ComponentOne Query on your computer. To use the C1QueryUI control, you can either register the C1Query80UI.ocx file located in the installation directory, or compile the user control yourself using the Visual Basic project supplied in the USERCTL directory. You need to add a C1QueryUI reference to your project selecting ComponentOne Query UI Control 8.0. It may also be a good idea to create a project group containing the C1Query10UI.vbp project and the tutorial project, it will allow you to set breakpoints in C1Query10UI code and explore how it works. Complete the following steps:

  1. Start a new project.

  2. Place the following controls on the form as shown in the figure: a C1QueryUI control (C1QueryUI1), a C1Query control (C1Query1), two Microsoft ADODC controls (Adodc1,2), a Microsoft DataGrid control (DataGrid1) and two command buttons (Command1,2).

  3. Set C1QueryUI1 control SchemaControl property to C1Query1.

    Set Adodc1 control ConnectionString to:

    Example Title
    Copy Code
    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;Persist Security Info=False
    

    Set the Adodc1 CommandType property to 2 – adCmdTable and the RecordSource property to Customers.

  4. Specify the schema for C1Query1, repeating steps 3-8 of Tutorial 2 - Using C1Query Schema Designer.

  5. Add the following code to the buttons’ Click event:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
       OK = C1Query1.BuildSQL
    
       If OK Then
    
          Adodc1.CommandType = adCmdText
    
          Adodc1.RecordSource = C1Query1.SQL
    
          Adodc1.Refresh
    
          Set DataGrid1.DataSource = Adodc1
    
        End If
    
    End Sub
    
     
    
    Private Sub Command2_Click()
    
       C1Query1.BuildSQL
    
       MsgBox C1Query1.SQL
    
    End Sub
    
  6. Add the following code to the form’s Load event:

    Example Title
    Copy Code
    Private Sub Form_Load()
    
       C1QueryUI1.SetLookup "Customers.CustomerID", Adodc2, "", "CompanyName", "CustomerID", True
    
       C1QueryUI1.SetLookup "Customers.CompanyName", Adodc2, "", "CompanyName", "", True
    
    End Sub
    

Run the Program and Observe the Following:

 

 


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

Product Support Forum  |  Documentation Feedback