Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ColumnHeadersHeightSizeMode Property
Collapse the table of content
Expand the table of content

DataGridView.ColumnHeadersHeightSizeMode Property

Gets or sets a value indicating whether the height of the column headers is adjustable and whether it can be adjusted by the user or is automatically adjusted to fit the contents of the headers.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public DataGridViewColumnHeadersHeightSizeMode ColumnHeadersHeightSizeMode { get; set; }
/** @property */
public DataGridViewColumnHeadersHeightSizeMode get_ColumnHeadersHeightSizeMode ()

/** @property */
public void set_ColumnHeadersHeightSizeMode (DataGridViewColumnHeadersHeightSizeMode value)

public function get ColumnHeadersHeightSizeMode () : DataGridViewColumnHeadersHeightSizeMode

public function set ColumnHeadersHeightSizeMode (value : DataGridViewColumnHeadersHeightSizeMode)

Not applicable.

Property Value

A DataGridViewColumnHeadersHeightSizeMode value indicating the mode by which the height of the column headers row can be adjusted. The default is EnableResizing.

Exception typeCondition

InvalidEnumArgumentException

The specified value when setting this property is not a valid DataGridViewColumnHeadersHeightSizeMode value.

When this property is set to AutoSize, the height of the column headers cannot be adjusted by the user.

To adjust the height of the column headers programmatically, use the AutoResizeColumnHeadersHeight method or set the ColumnHeadersHeight property.

To set the sizing mode for the row headers, use the RowHeadersWidthSizeMode property.

For cell contents to wrap onto multiple lines when the column headers are resized, the cell style in effect for the cell must have a WrapMode property value of True.

For more information about header sizing, see Sizing Options in the Windows Forms DataGridView Control.

NoteNote:

The DataGridView control does not support double buffering. If DoubleBuffered is set to true in a derived DataGridView control, users will not receive visual feedback when resizing rows, columns, or headers or when reordering columns.

The following code example illustrates how to use this property in a DataGridView control intended primarily for display. In this example, the visual appearance of the control is customized in several ways and the control is configured for limited interactivity. This example is part of a larger example available in the DataGridViewCellStyle class overview.

// Configures the appearance and behavior of a DataGridView control.
private void InitializeDataGridView()
{
    // Initialize basic DataGridView properties.
    dataGridView1.Dock = DockStyle.Fill;
    dataGridView1.BackgroundColor = Color.LightGray;
    dataGridView1.BorderStyle = BorderStyle.Fixed3D;

    // Set property values appropriate for read-only display and 
    // limited interactivity. 
    dataGridView1.AllowUserToAddRows = false;
    dataGridView1.AllowUserToDeleteRows = false;
    dataGridView1.AllowUserToOrderColumns = true;
    dataGridView1.ReadOnly = true;
    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;
    dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None;
    dataGridView1.AllowUserToResizeColumns = false;
    dataGridView1.ColumnHeadersHeightSizeMode = 
        DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
    dataGridView1.AllowUserToResizeRows = false;
    dataGridView1.RowHeadersWidthSizeMode = 
        DataGridViewRowHeadersWidthSizeMode.DisableResizing;

    // Set the selection background color for all the cells.
    dataGridView1.DefaultCellStyle.SelectionBackColor = Color.White;
    dataGridView1.DefaultCellStyle.SelectionForeColor = Color.Black;

    // Set RowHeadersDefaultCellStyle.SelectionBackColor so that its default
    // value won't override DataGridView.DefaultCellStyle.SelectionBackColor.
    dataGridView1.RowHeadersDefaultCellStyle.SelectionBackColor = Color.Empty;

    // Set the background color for all rows and for alternating rows. 
    // The value for alternating rows overrides the value for all rows. 
    dataGridView1.RowsDefaultCellStyle.BackColor = Color.LightGray;
    dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.DarkGray;

    // Set the row and column header styles.
    dataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
    dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Black;
    dataGridView1.RowHeadersDefaultCellStyle.BackColor = Color.Black;

    // Set the Format property on the "Last Prepared" column to cause
    // the DateTime to be formatted as "Month, Year".
    dataGridView1.Columns["Last Prepared"].DefaultCellStyle.Format = "y";

    // Specify a larger font for the "Ratings" column. 
    using (Font font = new Font(
        dataGridView1.DefaultCellStyle.Font.FontFamily, 25, FontStyle.Bold))
    {
        dataGridView1.Columns["Rating"].DefaultCellStyle.Font = font;
    }

    // Attach a handler to the CellFormatting event.
    dataGridView1.CellFormatting += new
        DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
}

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2015 Microsoft