Using Data Sources with the DataGridView Control - How to edit the columns of a DataGridView control
(Page 4 of 5 )
Figure 14-8 shows how to edit the columns of a DataGridView control using the Edit Columns dialog box. From this dialog box, you can remove columns from the grid by selecting the column and clicking the Remove button. You can also change the order of the columns by selecting the column you want to move and clicking the up or down arrow to the right of the list of columns.
Finally, you can use the Add button in this dialog box to add a column to the grid. You might need to do that if you delete a column and then decide you want to include it. You can also use the dialog box that’s displayed when you click the Add button to add unbound columns to the grid. You’ll learn how to do that in the next chapter.
Once you’ve got the right columns displayed in the correct order, you can edit the properties for a column by selecting the column to display its properties in the Bound Column Properties window. When you see the Product Maintenance form in the next figure, for example, you’ll see that I changed the HeaderText property for the ProductCode and UnitPrice columns to provide shorter names for the column headers. In addition, I changed the Width property of each column as appropriate. Finally, I used the DefaultCellStyle property to apply currency formatting to the UnitPrice column.
The dialog box for editing the columns of a DataGridView control

Common properties of a column
Property | Description |
HeaderText | The text that’s displayed in the column header. |
Width | The number of pixels that are used for the width of the column. |
DefaultCellStyle | The style that’s applied to the cell. You can use dialog boxes to set style elements such as color, format, and alignment. |
Description
- You can use the Edit Columns dialog box to control which columns are displayed in the grid and to edit the properties of those columns. To display this dialog box, choose the Edit Columns command from the smart tag menu for the control
- To remove columns from the grid, select the column and click the Remove button.
- To add a column to the grid, click the Add button and then complete the dialog box that’s displayed. This dialog box lets you add both bound and unbound columns. See chapter 15 for more information on adding unbound columns.
- To change the order of the columns, select the column you want to move and click the up or down arrow to the right of the list of columns.
- To edit the properties for a column, select the column and use the Bound Column Properties window to edit the properties.
Figure 14-8. How to edit the columns of a DataGridView control
Next: A Product Maintenance application that uses 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.
|
|