|
Now it is moment to build a form
to edit the Orders data. Right-click on the project in
Solution Explorer Add New Item and choose the Windows Form
icon, giving it a name of Orders paper. VS will present an
empty form to work with.
If your Data Sources window is
not open, click the top line Data menu and choose Show Data
Sources. In your tree, you should observe the dataset and data
tables. To the right of every table is a dropdown that allows
you to select among implementing it as a Data layer or free
form Details controls. You can additional expand the table to
observe the data fields and likewise select which control to
make use of to execute the field in free form controls. This
Wizard can be customized through the Tools / Options / Windows
Forms Designer / Data UI Customization to permit custom
controls to be planned as well.
Most presentations often favor
to have parent screens shown in Details format so in Data
Sources, change the format for the Orders table to Details.
Now appears the exciting part--drag the Orders table since the
Data Sources window and fall it in the upper left corner of
the empty form in the design surface of Visual Studio. The
Data Sources Wizard will make each of the controls in the
table, according to the default chosen. You may as well drag
the fields one at a time from Data Sources pane, but it is a
lot faster to just have them all generate at once. You will
notice that each manage is correctly named and bound to the
right field in the table. The wizard as well creates a label
for every control, using the explanation property if
accessible and otherwise, the name of the field, putting in
spaces where wanted.
More than presently the
controls, the Wizard has added functionality to our appearance
by adding a Data Navigation stripe that permits the user to
switch among records using VCR style buttons. The Wizard as
well added the components compulsory to present connectivity
and binding among the dataset and database. If you open the
code window, you will observe that the Wizard has yet added a
line of code to call the Table Adapter module to fill up the
Data layer component. If you put the project to be the Startup
project and the properties of the project to show this form at
startup, you can build and run the solution now and see the
form fully functional, showing all the records in the Orders
table. There is a small work to do to get the Combo Box
controls working properly, but the form is essentially
functional.
To obtain the Combo Boxes
useful, we can open the Data combination and put in the
Customer and Employee tables generate separate datasets for
them. After building the project, you can refresh the Data
Sources window to see the new tables or add new data sources
if you put them in a different Data inner set.
Back on the form, drag the
Employee table from the Data Source and drop it on the combo
box. The first thing you notice is another Binding Source
component is added to for the Employee table. If you select
the employee combo box control, you will notice that the
proper settings for the Data Source, Display Member and Value
Member have been put and the binding has been changed as of
Text to preferred Value. This is what Microsoft calls ‘Connect
the dots’ you can drag and drop a table to any list driven
control. The wizard takes the primary key for the Value Member
and the 1st character field for the Display Member property.
You can drag the Customer
table to the Customer combo box in the similar way and a
required Source component will be added for it as well. If you
open the code at the back the form, you will too notice that
VS has added code to the Orders Form class to fill up the
tables with data as of the dataset for each binding source
added to the form.
|