dotnetmonitor.com |
|
|||||||||||||||||||||||||
| You can retrieve
DataGridViewCellStyle objects from various properties of the DataGridView,
DataGridViewColumn, DataGridViewRow, and DataGridViewCell classes and their
derived classes. If one of these properties has not yet been set, retrieving
its value will create a new DataGridViewCellStyle object. You can also
instantiate your own DataGridViewCellStyle objects and assign them to these
properties.
You can avoid unnecessary duplication of style information by sharing DataGridViewCellStyle objects among multiple DataGridView elements. Because the styles set at the control, column, and row levels filter down through each level to the cell level, you can also avoid style duplication by setting only those style properties at each level that differ from the levels above. This is described in more detail in the Style Inheritance section that follows.
The following table lists the primary properties that get or set DataGridViewCellStyle objects.
As mentioned above, getting the value of a style property automatically instantiates a new DataGridViewCellStyle object if the property has not been previously set. To avoid creating these objects unnecessarily, the row and column classes have a HasDefaultCellStyle property that you can check to determine whether the DefaultCellStyle property has been set. Similarly, the cell classes have a HasStyle property that indicates whether the Style property has been set.
Each of the style properties has a corresponding PropertyNameChanged event on the DataGridView control. For row, column, and cell properties, the name of the event begins with "Row", "Column", or "Cell" (for example, RowDefaultCellStyleChanged). Each of these events occurs when the corresponding style property is set to a different DataGridViewCellStyle object. These events do not occur when you retrieve a DataGridViewCellStyle object from a style property and modify its property values. To respond to changes to the cell style objects themselves, handle the CellStyleContentChanged event. |
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||