Chapter 19 Quick Reference


Chapter 19 Quick Reference

To

Do this

Establish a connection to database tables in a project

Use the Data Source Configuration Wizard to link the project to a database, create a dataset, and fill the Data Sources window with a representation of the selected tables.

Create a data grid view object on a form to display an entire database table

Drag a table icon from the Data Sources window to the form. Then resize the data grid view object so that each column is visible.

Preview data bound to a data grid view object

Click the data grid view object's shortcut arrow to display the DataGridView Tasks list box. Click the Preview Data command, and then click the Preview button in the Preview Data dialog box.

Remove a column from a data grid view object

Click the data grid view object's shortcut arrow to display the DataGridView Tasks list box. Click the Edit Columns command, click the column that you want to remove in the Selected Columns list box, and then click the Remove button.

Sort the records in a grid at run time

Click the column header that you want to sort by. Visual Studio sorts the grid alphabetically based on that column.

Reverse the direction of a grid sort at run time

Click the column header a second time to reverse the direction of the sort (from A–Z to Z–A).

Change the default column width for a column in a data grid view object

In the Properties window, click the Columns property and then the ellipses button. In the Edit Columns dialog box, adjust the Width property.

Hide column headers in a data grid view object

Set the ColumnHeadersVisible property to False.

Create an alternating color scheme for rows within a data grid view object

Pick a color for alternating rows by using the AlternatingRowsDefaultCellStyle property. In the CellStyle Builder dialog box, adjust the BackColor property. The color that you select will alternate with white.

Change the color of gridlines in a grid

Adjust the GridColor property.

Add a second data grid view object to a form

Drag a second table from the Data Sources window to the form. Resize and customize the table, taking care to make the form large enough to display all the database columns and records that your user will want to see. If you want to add a second navigation bar to the form to provide access to the table, create a second BindingNavigator control on the form, and set its BindingSource property to the binding source representing the new table you created.

Prevent the user from editing or changing the data in a data grid view object

Set the grid's ReadOnly property to True.

Write changes made in the grid back to the underlying database

Verify that the data grid view object's ReadOnly property has been set to False. Then at run time, use the Save button on the navigation bar to save your changes and update the database. Alternatively, you can use the table adapter's Update method within program code.



Microsoft Visual Basic 2005 Step by Step
Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))
ISBN: B003E7EV06
EAN: N/A
Year: 2003
Pages: 168

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net