Tutorials > 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:
Start a new project.
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).
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.
Specify the schema for C1Query1, repeating steps 3-8 of Tutorial 2 - Using C1Query Schema Designer.
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 |
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 |
A split bar divides the two C1QueryFrame panels. You can resize the panels by drag and drop on that split bar. This functionality is built in the C1QueryUI user control.
Try editing values for fields of different data types. For example: Orders.OrderData – date type, Products.Discontinued – Boolean type, [Order Details].Discount – numeric type. Dates will be edited with a date-time picker control, Boolean values – with a Yes/No combo box, numeric values will be edited in a TextBox with masking functionality, not allowing the user to enter invalid characters. This functionality is implemented in the C1QueryUI user control.
Select the Customers.CustomerID or Customers.CustomerName field in an elementary condition, and then click on the right side of the condition. You will see a combo box filled with company names for user selection.
Examine the source code of C1QueryUI user control in the USERCTL directory and try modifying the properties of the controls used as custom editors (date-time picker, combo boxes, and so on). Then compile the user control project, open the tutorial project again and see how the changes to custom editors immediately affect the editors in the tutorial.