- DataGridView Overview
- Basic Data Binding with the DataGridView
- Controlling Modifications to Data in the Grid
- Programmatic DataGridView Construction
- Custom Column Content with Unbound Columns
- Displaying Computed Data in Virtual Mode
- Using the Built-In Column Types
- Built-In Header Cells
- Handling Grid Data Edits
- Automatic Column Sizing
- Column and Row Freezing
- Using the Designer to Define Grids
- Column Reordering
- Defining Custom Column and Cell Types
- Utilizing Cell-Oriented Grid Features
- Formatting with Styles
- Where Are We?
Where Are We?
This chapter has covered all the main features of the DataGridView control. It focused a lot on the code involved and what the capabilities were. For most common cases, you’ll be able to get what you need simply by defining the columns in the designer, setting up some data binding with the Data Sources window, and maybe mixing in some custom code and event handlers. The DataGridView control is considerably simpler to use and more flexible and powerful than the DataGrid control from .NET 1.0, and you should always favor using the DataGridView for new applications that will present tabular data or something that needs to be presented in a grid format.
Some key takeaways from this chapter are:
- Setting the DataSource and DataMember properties on the DataGridView to a BindingSource that binds to the data source is the standard way of using the grid.
- Use the Edit Columns functionality in the designer Smart Tag for the easiest way to edit and customize the bound and unbound column types and properties.
- Bound columns will use automatic type conversion and formatting similar to the Binding object, as discussed in Chapter 4.
- To add a custom cell type, you create a custom column type derived from DataGridViewColumn, and a custom cell type derived from DataGridViewCell or one of the derived built-in cell types.
Next we’ll go deeper into the data-binding mechanisms used in Windows Forms, specifically the interfaces that you need to understand and implement in order to create any custom data objects or collections that you want to use for data binding. You will gain a better understanding of what the data-bound controls are looking for when you set up data binding, and how they use what they find.