DataGridColumnStyle Class


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Specifies the appearance, text formatting, and behavior of a System.Windows.Forms.DataGrid control column. This class is abstract.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)


type DataGridColumnStyle = 
        inherit Component
        interface IDataGridColumnStyleEditingNotificationService


In a derived class, initializes a new instance of the DataGridColumnStyle class.


Initializes a new instance of the DataGridColumnStyle class with the specified PropertyDescriptor.


Gets or sets the alignment of text in a column.


Gets a value indicating whether the component can raise an event.(Inherited from Component.)


Gets the IContainer that contains the Component.(Inherited from Component.)


Gets the DataGridTableStyle for the column.


Gets a value that indicates whether the Component is currently in design mode.(Inherited from Component.)


Gets the list of event handlers that are attached to this Component.(Inherited from Component.)


Gets the height of the column's font.


This API supports the product infrastructure and is not intended to be used directly from your code. Gets the AccessibleObject for the column.


Gets or sets the text of the column header.


Gets or sets the name of the data member to map the column style to.


Gets or sets the text that is displayed when the column contains null.


Gets or sets the PropertyDescriptor that determines the attributes of data displayed by the DataGridColumnStyle.


Gets or sets a value indicating whether the data in the column can be edited.


Gets or sets the ISite of the Component.(Inherited from Component.)


Gets or sets the width of the column.


When overridden in a derived class, initiates a request to interrupt an edit procedure.


Suspends the painting of the column until the EndUpdate method is called.


Throws an exception if the System.Windows.Forms.DataGrid does not have a valid data source, or if this column is not mapped to a valid property in the data source.


Informs the System.Windows.Forms.DataGrid that the user has begun editing the column.

System_CAPS_protmethodCommit(CurrencyManager, Int32)

When overridden in a derived class, initiates a request to complete an editing procedure.


Notifies a column that it must relinquish the focus to the control it is hosting.


Gets the AccessibleObject for the column.


Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.)


Releases all resources used by the Component.(Inherited from Component.)


Releases the unmanaged resources used by the Component and optionally releases the managed resources.(Inherited from Component.)

System_CAPS_protmethodEdit(CurrencyManager, Int32, Rectangle, Boolean)

Prepares a cell for editing.

System_CAPS_protmethodEdit(CurrencyManager, Int32, Rectangle, Boolean, String)

Prepares the cell for editing using the specified CurrencyManager, row number, and Rectangle parameters.

System_CAPS_protmethodEdit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean)

When overridden in a deriving class, prepares a cell for editing.


Resumes the painting of columns suspended by calling the BeginUpdate method.


Enters a DBNull.Value into the column.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.(Inherited from Component.)

System_CAPS_protmethodGetColumnValueAtRow(CurrencyManager, Int32)

Gets the value in the specified row from the specified CurrencyManager.


Serves as the default hash function. (Inherited from Object.)


Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)


When overridden in a derived class, gets the minimum height of a row.

System_CAPS_protmethodGetPreferredHeight(Graphics, Object)

When overridden in a derived class, gets the height used for automatically resizing columns.

System_CAPS_protmethodGetPreferredSize(Graphics, Object)

When overridden in a derived class, gets the width and height of the specified value. The width and height are used when the user navigates to DataGridTableStyle using the DataGridColumnStyle.


Returns an object that represents a service provided by the Component or by its Container.(Inherited from Component.)


Gets the Type of the current instance.(Inherited from Object.)


Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)


Redraws the column and causes a paint message to be sent to the control.


Creates a shallow copy of the current Object.(Inherited from Object.)


Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_protmethodPaint(Graphics, Rectangle, CurrencyManager, Int32)

Paints the DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, and row number.

System_CAPS_protmethodPaint(Graphics, Rectangle, CurrencyManager, Int32, Boolean)

When overridden in a derived class, paints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, and alignment.

System_CAPS_protmethodPaint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean)

Paints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, background color, foreground color, and alignment.


Allows the column to free resources when the control it hosts is not needed.


Resets the HeaderText to its default value, null.

System_CAPS_protmethodSetColumnValueAtRow(CurrencyManager, Int32, Object)

Sets the value in a specified row with the value from a specified CurrencyManager.


Sets the System.Windows.Forms.DataGrid control that this column belongs to.


Sets the System.Windows.Forms.DataGrid for the column.


Returns a String containing the name of the Component, if any. This method should not be overridden.(Inherited from Component.)

System_CAPS_protmethodUpdateUI(CurrencyManager, Int32, String)

Updates the value of a specified row with the given text.


Occurs when the Alignment property value changes.


Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)


Occurs when the column's font changes.


Occurs when the HeaderText property value changes.


Occurs when the MappingName value changes.


Occurs when the NullText value changes.


Occurs when the PropertyDescriptor property value changes.


Occurs when the ReadOnly property value changes.


Occurs when the Width property value changes.


Informs the DataGrid control that the user has begun editing the column.

The collection of DataGridColumnStyle objects (the GridColumnStylesCollection) is accessed through the System.Windows.Forms.DataGrid control's TableStyles property.

The System.Windows.Forms.DataGrid control automatically creates a collection of DataGridColumnStyle objects for you when you set the DataSource property to an appropriate data source. The objects created actually are instances of one of the following classes that inherit from DataGridColumnStyle: DataGridBoolColumn or DataGridTextBoxColumn class.

To format the data display, set the Format property of the DataGridTextBoxColumn class to one of the formatting values. For more information about valid formatting values, see Formatting Types in the .NET Framework and Custom Date and Time Format Strings.

You can also create your own set of DataGridColumnStyle objects and add them to the GridColumnStylesCollection. When you do so, you must set the MappingName of each column style to the ColumnName of a DataColumn to synchronize the display of columns with the actual data.


Always create DataGridColumnStyle objects and add them to the GridColumnStylesCollection before adding DataGridTableStyle objects to the GridTableStylesCollection. When you add an empty DataGridTableStyle with a valid MappingName value to the collection, DataGridColumnStyle objects are automatically generated for you. Consequently, an exception will be thrown if you try to add new DataGridColumnStyle objects with duplicate MappingName values to the GridColumnStylesCollection.

When one of the derived classes is instantiated by a System.Windows.Forms.DataGrid control, the class created depends on the DataType of the DataColumn associated with the DataGridColumnStyle object. For example, a DataColumn with its DataType set to System.Boolean will be associated with a DataGridBoolColumn. To determine the type of any DataGridColumnStyle, use the GetType method.

To create your own column classes, you can inherit from DataGridColumnStyle. You might want to do this in order to create special columns that host controls, as exemplified by the DataGridTextBox class, which hosts the TextBox control. For example, you can host an Image control to show pictures in columns, or you can create your own user control to host in the column.

The functionality of the DataGridColumnStyle shouldn't be confused with that of the DataColumn. Whereas the DataColumn contains the properties and methods appropriate to creating a data table's schema, the DataGridColumnStyle contains the properties and methods related to the appearance of an individual column on the screen.

If a row contains a DBNull.Value, the text displayed in the column can be set with the NullText property.

The DataGridColumnStyle class also allows you to specify the behavior of a column while its data is being changed. The BeginUpdate and EndUpdate methods temporarily suspend the drawing of the column while large updates are being made to the column's data. Without this functionality, every change in every cell of the grid would be immediately drawn; this could be distracting to the user and a performance liability.

Several methods allow monitoring of the column as it is edited by the user, including the Edit and Commit events.

Most of the properties and methods of the class are tailored to controlling a column's appearance. But a few, such as the GetColumnValueAtRow and SetColumnValueAtRow allow you to examine and change the value in a specified cell.

Notes to Implementers:

When you inherit from DataGridColumnStyle, you must override the following members: Abort, Commit, Edit, and Paint (twice).

The following code example creates a DataGridColumnStyle that hosts a DateTimePicker control.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top