Using Data Sources with the DataGridView Control - How to edit the properties of a DataGridView control
(Page 3 of 5 )
When you generate a DataGridView control from a data source, Visual Studio usually sets the properties of this control and the other objects it creates the way you want them. However, if you want to modify any of these properties, you can do that just as you would for any other type of object. In particular, you’ll probably want to edit the properties of the DataGridView control to change its appearance and function.
To change the most common properties of a DataGridView control, you can use its smart tag menu as shown in figure 14-7. From this menu, you can create a read-only data grid by removing the check marks from the Enable Adding, Enable Editing, and Enable Deleting check boxes. Or, you can let a user reorder the columns by checking the Enable Column Reordering check box.
In addition to editing the properties for the grid, you may want to edit the properties for the columns of the grid. For example, you may want to apply currency formatting to a column, or you may want to change the column headings. To do that, you can select the Edit Columns command to display the Edit Columns dialog box shown in the next figure.
When you run an application that uses a DataGridView control, you can sort the rows in a column by clicking in the header at the top of the column. The first time you do this, the rows are sorted in ascending sequence by the values in the column; the next time, in descending sequence. Similarly, you can drag the column separators to change the widths of the columns. Last, if the Enable Column Reordering option is checked, you can reorder the columns by dragging them. These features let the user customize the presentation of the data.
The smart tag menu for a DataGridView control

Description
- You can use the smart tag menu of a DataGridView control to edit its most commonly used properties.
- To edit the columns, select the Edit Columns command to display the Edit Columns dialog box. Then, you can edit the columns as described in the next figure.
- To prevent a user from adding, updating, or deleting data that’s displayed in the DataGridView control, uncheck the Enable Adding, Enable Editing, or Enable Deleting check boxes.
- To allow a user to reorder the columns in a DataGridView control by dragging them, check the Enable Column Reordering check box.
- You can edit other properties of a DataGridView control by using the Properties window for the control.
Figure 14-7. How to edit the properties of a DataGridView control
Next: How to edit the columns of a DataGridView control >>
More Visual Basic.NET Articles
More By Murach Publishing
|
This article is excerpted from chapter 14 of the book Murach's Visual Basic 2005, written by Anne Boehm (Murach, 2006; ISBN: 1890774383). Check it out today at your favorite bookstore. Buy this book now.
|
|