Step 5: Extending the generated code
After you have created the RapTier project and generated code, you may want to
customize the output code to suite your specific requirements. Let's consider a
few examples so you could see for yourself how easy you can modify the
generated code.
We will perform the following tasks:
a. Delete the Order ID label and the text box.
b. Replace the Order Date, Required Date, and Shipped Date
text boxes with the DateTimePicker controls.
c. Replace Customer ID, Employee ID, Ship Via text boxes
with the lookup combo-boxes.
d. Add a DataGrid Control to display the data in a master-detail format.
a. Delete the Order ID label and the text box
-
Open the OrdersRowEditor user control in the Windows Form Designer
-
Delete the _lblOrderID and _txtOrderID
controls.
-
Switch to the Code Editor.
-
Delete the _txtOrderID data binding code from the SetDataBinding method.
Code that needs to be removed:
C#
this.("Text", dataSource, "Orders.OrderID");
VB.NET
Me.("Text", dataSource, "Orders.OrderID")
b. Replace the Order Date, Required Date, and Shipped Date text boxes with
DateTimePicker controls
-
Open the OrdersRowEditor user control in the Windows Form Designer
-
Replace the _txtOrderDate text box by a DateTimePicker
control
-
Rename the new DateTimePicker to _orderDatePicker
-
Switch to the Code Editor
-
Replace _txtOrderDate by _orderDatePicker in the SetDataBinding
method
C#
Old: this._txtOrderDate.DataBindings.Add("Text",
dataSource, "Orders.OrderDate");
New: this._orderDatePicker.DataBindings.Add("Text",
dataSource, "Orders.OrderDate");
VB.NET
Old: Me._txtOrderDate.DataBindings.Add("Text",
dataSource, "Orders.OrderDate")
New: Me._orderDatePicker.DataBindings.Add("Text",
dataSource, "Orders.OrderDate")
Perform similar operation for the Required Date and Shipped Date fields.
The Figures 5.2 and 5.3 below show the result of these changes.
Figure 5.1

Figure 5.2
c. Replace Customer ID, Employee ID, Ship Via text boxes with the lookup
combo-boxes
-
Open the OrdersRowEditor user control in the Windows Form Designer
-
Using the Properties window, change the Text property of _lblCustomerID
from Customer ID to Customer
-
Delete the _txtCustomerID
control.
-
Add a ComboBox control to the design panel instead of _txtCustomerID
-
Using the Properties window, set the DropDownStyle property of
the combo box to DropDownList and rename it to _customerComboBox.
-
Switch to the Code Editor.
-
Remove the _txtCustomerID data binding code from the SetDataBinding
method.
-
Add the following _customerComboBox data binding code to the SetDataBinding
method:
C#:
_customerComboBox.DataSource = dataSource;
_customerComboBox.ValueMember =
"Customers.CustomerID";
_customerComboBox.DisplayMember =
"Customers.CompanyName";
_customerComboBox.DataBindings.Add("SelectedValue", dataSource,
"Orders.CustomerID");
VB.NET:
_customerComboBox.DataSource = dataSource
_customerComboBox.ValueMember = "Customers.CustomerID"
_customerComboBox.DisplayMember =
"Customers.CompanyName"
_customerComboBox.DataBindings.Add("SelectedValue", dataSource,
"Orders.CustomerID")
The Figures 5.4 and 5.5 show the result of the above changes.

Figure 5.3

Figure 5.4
d. Add a DataGrid Control to display the data in a master-detail format
-
Open the OrdersTableEditor user control in the Windows Form Designer
-
Select the _rowEditor control and change its Dock property from Fill
to None
-
Move the _rowEditor
contol to the right-bottom corner of the design panel.
-
Drop TabControl to the design panel and create two tabs Order and Order
Details
-
Drag the _rowEditor control to the Order
tab.
-
Set the Dock property of the _rowEditor control to Fill
-
Set the Dock property of the TabControl object to Fill
-
Select the Order Details tab and add a DataGrid
control to it.
-
Using the Properties window, rename the new DataGrid control to _orderDetailsDataGrid
and set the following properties:
-
Dock to Fill
-
CaptionVisible to false
-
ReadOnly to true
-
Switch to the code view.
-
In the LoadData
method, uncomment the master-detail code.
-
Add the following _orderDetailsDataGrid data binding code to the LoadData
method:
C#
_orderDetailsDataGrid.SetDataBinding(_dataSet,"Orders.OrdersOrder
Details");
VB.NET
_orderDetailsDataGrid.SetDataBinding(_dataSet,"Orders.OrdersOrder
Details")
Where
Orders is the name of the master table and
OrdersOrder Details is the name of the master-detail relationship declared in the DataSet object.
Note: If you are using MS
SQL server Northwind database, the data binding code must be as follows:
C#
_orderDetailsDataGrid.SetDataBinding(_dataSet,"Orders.FK_Order_Details_Orders");
VB.NET
_orderDetailsDataGrid.SetDataBinding(_dataSet,"Orders.FK_Order_Details_Orders")

Figure 5.5

Figure 5.6
Conclusion
This tutorial has been written to give
RapTier users an insight into how the generated applications can be
customized to fit your development requirements.
If you have questions or comments please address them to our support team at
support@SharpPower.com. We welcome your feedback.
For more information about the generated classes, methods and properties see
the User Guide section in the documentation.