Defining a Custom Column Type

So now you have a custom cell class that could be used in the grid, but you also want to have a custom column class that contains StatusCellsand can be used for setting up the grid and data binding. If you were going to use the custom cell type completely programmatically, you could just construct an instance of the DataGridViewColumn base class and pass in an instance of aStatusCell to the constructor, which sets that as the CellTemplate for the column. However, that approach wouldn't let you use the designer column editors covered in Figures 6.4 and 6;5 to specify a bound or unbound column ofStatusCells. To support that, you need to implement a custom column type that the designer can recognize. As long as you're implementing your own column type, you also want to expose a way to set what the default value of the Statuslmage should be for new rows that are added. The implementation of th^StatusColumn class is shown in Listing 6.5.

0 0

Post a comment