Once you "finish" with a TableAdapter configuration, you're almost ready to run the code that's been generated. As I step through the demos you've seen so many times, let's take the next step and drag a TableAdapter from the Data Sources window to a Windows Form. But waitbefore you drag anything from the Data Sources window, click the selected TableAdapter icon and click the down arrow. This exposes a menu, as shown in Figure 6.31. Figure 6.31. Choosing how the TableAdapter is to be rendered when dragged to a Form.
By default, dragging a TableAdapter from the Data Sources window incorporates a DataGridView as the bound control. I'll start from there and re-visit how "Details" binding works a bit later.
Customizing the Generated UINotice that the "Fill" button on the FillToolStrip does no look much like a Buttonor, at least, I don't think it does. To fix this, you can right-click on the "Fill" button and choose "Set Image" from the menu, as shown in Figure 6.35. Choose an appropriate image file and set the DisplayStyle to "Image" or "Image and Text". This will let your users have a better chance at finding the "Fill" button. No, I don't think it's a good idea to pre-populate the Form with datanot until the user has chosen the input parameters. This makes your Form load faster. Sure, if you save the user preferences, you might return to the last set of parameters and execute Fill when the form is loaded using those parameters. Figure 6.34. The controls added to the Tool Tray area of the Form by drag-and-drop.
Figure 6.35. Customizing the "FillToolStrip" button.
Since I'm focusing on parameters, I need to make a few more changes to the generated codeat least, indirectly. I need to set the parameter default values (as I have already done in Figure 6.34). Click on each of the TextBox controls in the FillToolStrip and set the Text property. Where do these default parameters come from? Well, I like to "remember" the parameters last used, so I save the values in a persisted application setting that's reloaded when the application is restarted. Using SmartTags to Manage Bound ControlsEach of the bound controls placed on the Form by the code generators can be further tuned by using the SmartTag exposed in the upper-right corner of the control. To see what's available for each bound control, I suggest you visit each control and click on the SmartTag and review what options are exposed. I clicked on the SmartTag exposed on the DataGridView to expose the "tasks" menu, as shown in Figure 6.36. Figure 6.36. Clicking the SmartTag exposes additional "task" settings.Note that these "tasks" permit you to easily enable DML changes, column reordering, and docking options. I talked about using this approach to make UI (instead of query) changes earlier in this chapter. You can also choose to edit or add columns to the DataGridView using this interface. One change you might want to make is to make sure any RO columns in the DataGridView Columns collection have their ReadOnly property set to True.
Binding to "Details"Just before I dragged the TableAdapter to the Form, I made a decision to use the default binding controlthe DataGridView. An alternative would be to choose "Details" from the menu shown in Figure 6.31. Let's see what happens when you make this choice.
Binding to Custom ControlsSure, you don't have to use a TextBox control to expose the contents of a TableAdapter column. You can navigate to the Data Source and click on each individual column returned by the query and choose the type of control to be used (as shown in Figure 6.39). By default, the code generators try to map appropriate bound controls to each column. This way, string and number columns are bound to TextBox controls, but pictures (TEXT, IMAGE, or VarChar(Max)) data types are mapped to Image controls. You can also code and specify custom bound controls. For columns you don't want users to change, you can set the bound control type to Labelat least, this works when binding using the "details" mode. Changing the type to "Label" has no impact on the RO status of the DataGridView column. Figure 6.39. Clicking on individual columns determines how the column is to be bound.
|