Designing the Application UI
The application consists of two forms. The first allows a user to enter activity information and the second allows for entry of the various kinds of tasks.
Rename the default form in the application to frmDeskTimeKeeper. Drop a DataGridView control from the Toolbox on the form. Next you need to specify the datasource for the DataGridView control. Select the DataGridView control, on the upper right-hand side, select the SmartTag that appears and specify dsActivitiesTasks, which you have already created, as the datasource (see Figure 3). (Note: Select the dataset dsActivitiesTasks not the DataTables (activities or tasks).)

Figure 3. Adding a Datasource: In this dialog, specify the datasource for the DataGridView.
|
|

Figure 4. DataGridView DataSource: In this dialog, you will bind the DataGridView control directly to the DsActivitiesTasks dataset. |
In the component tray you will notice that Visual Studio adds an instance of the
dsActivitesTasks and also another component called
dsActvitiesTasksBindingSource. You really don't need the Binding sourceonly the DataSet so that you can set the binding directly to the DataGridView control. You need to bind directly to the DataSet instance, so select the BindingSource and delete it.. Next reselect the SmartTag on the DataGridView control and specify its data source. You will notice that a new source is available, which is
frmActivities List Instances. Below it you will find
dsActivitiesTasks (see
Figure 4), which you should select. In doing so you will bind the DataGridView control directly to the
dsActivitiesTasks dataset.
 | |
| Figure 5. Form Activities UI: In this dialog, you'll set the text for three buttons used by the application. |
Next you need to set the DataMember property for the DataGridView to the activities DataTable. As you do this you will notice that the designer now shows the columns of the activities table on the DataGridView.
Customizing the DataGridView
The DataGridView shows all the columns of the activities DataTable. Some columns, such as the auto-generated activityid column, don't need to be displayed to the end user. Moreover, the taskid should ideally display the tasks instead of the IDs, and the user should be able to choose from the tasks DataTable. The taskid column would be better suited as a drop-down column, displaying the tasks, in order to simplify data entry.
You need to edit the properties of the columns in the DataGridView to achieve these effects. Select the SmartTag on the DataGridView control and choose Edit Columns.
Set the properties as shown in Table 3:
Table 3. Setting Column Properties:
| Column
|
Property
|
| activityid |
Visible=False |
| Taskid |
ColumnType= DataGridViewComboBoxColumn DataSource= DsActivitiesTasks DataMember= tasks.task ValueMember=tasks.taskid |
| description |
Width=180 |
After customizing the DataGridView the next step is adding three buttons to the form. Name them btnEditAddTasks, btnSave, and btnDelete, and set their text property as shown in Figure 5. Then resize the form appropriately.