Microsoft Visual Basic 2010 Step by Step eBook

(Tina Meador) #1

482 Part IV Database and Web Programming


You might want to scan the Properties window for additional property settings and
customizations. There are several possibilities if you look closely at the list of formatting
options. Remember, these property settings affect all the columns in a table, not just
individual columns.

Adding a Second Data Grid View Object


To provide your users with a data-rich user interface containing multiple views of your
database, you should consider adding a second data grid view object to your form. After
you have established a dataset in the Data Sources window, it is relatively straightforward to
add an additional DataGridView control bound to a second table within the dataset. If you
connect to a second database table (rather than a second copy of the first table), you can
also add a second navigation bar to the form and use it to control the second data grid view
separately. In the following exercise, you’ll add a second version of the Faculty table to your
form that contains a different set of fields with faculty information.

Bind a second DataGridView control to the Faculty table


  1. Expand the size of the form or reduce the height of the FacultyDataGridView object to
    make room on the form for a second data grid view object below the first.
    Because my screen resolution is probably smaller than yours, I’m reducing the height of
    the FacultyDataGridView object and making the form a little bigger to accommodate
    the second data grid view.

  2. Open the Data Sources window, if it is not currently visible.

  3. Drag the Faculty table from the Data Sources window to below the
    FacultyDataGridView object.
    Visual Studio creates a second data grid view object named FacultyDataGridView1
    on the form. In this case, you’re adding a second copy of the Faculty table to your
    program. However, if your database has multiple tables, an interesting thing to do
    is add a second table to the form, which will give you completely different database
    records to look at.

  4. Right-click the new FacultyDataGridView1 object, and then click the Edit Columns
    command.
    The Edit Columns dialog box opens.

  5. Select and remove the ID, E-mail Address, Department, Faculty Type, and Business
    Phone columns.

Free download pdf