Difference between revisions of "Visual Basic and the DataGridView Control"

From Techotopia
Jump to: navigation, search
(New page: The Visual Basic ''DataGridView'' control provides a table in which rows and columns from a database table can be displayed and modified. In this chapter we will explore the steps necessar...)
 
Line 2: Line 2:
  
 
==
 
==
 +
 +
== Adding a DataGridView Control ==
 +
[[Image:Example.jpg]]
 +
Now that we have our data sources configured the next step is to add a DataGridView control to our application. Access the ''Toolbox'' and drag and drop the ''DataGridView'' control onto the form. Resize the control so that fills the entire form and set the ''Anchor'' property in the ''Properties'' panel so that all sides are anchored (such that when teh form is resized the DataGridView will also resize).
 +
 +
If the ''Data Sources'' panel is not visible, select the ''Data->Show Data Sources'' menu option. Once visible, click and drag the ''Customers'' table from the ''Data Sources'' panel over the DataGridView control on the form. The form will update to display a columns, and rows. Press'''F5'' to build and run the application:
 +
 +
[[Image:Exampl.jpg]]
 +
 +
== Customizing the DataGridView Control ==
 +
 +
Various aspects of the DataGridView control can be configured using Visual Studio, such as the columns displayed.
 +
 +
To edit the columns displayed in the grid, right click with the mouse over the control in the form designer and select ''Edit Columns...''. The following dialog will appear. Use the ''Add...'' and ''Remove'' buttons to configure the columns displayed by the grid:
 +
 +
[[Image:Exampl.jpg]]

Revision as of 19:18, 9 August 2007

The Visual Basic DataGridView control provides a table in which rows and columns from a database table can be displayed and modified. In this chapter we will explore the steps necessary to build a DataViewGrid into a Visual Basic application and connect it to a database table.

==

Adding a DataGridView Control

Example.jpg Now that we have our data sources configured the next step is to add a DataGridView control to our application. Access the Toolbox and drag and drop the DataGridView control onto the form. Resize the control so that fills the entire form and set the Anchor property in the Properties panel so that all sides are anchored (such that when teh form is resized the DataGridView will also resize).

If the Data Sources panel is not visible, select the Data->Show Data Sources menu option. Once visible, click and drag the Customers table from the Data Sources panel over the DataGridView control on the form. The form will update to display a columns, and rows. Press'F5 to build and run the application:

File:Exampl.jpg

Customizing the DataGridView Control

Various aspects of the DataGridView control can be configured using Visual Studio, such as the columns displayed.

To edit the columns displayed in the grid, right click with the mouse over the control in the form designer and select Edit Columns.... The following dialog will appear. Use the Add... and Remove buttons to configure the columns displayed by the grid:

File:Exampl.jpg