Cet article a fait l’objet d’une traduction automatique. Pour afficher l’article en anglais, activez la case d’option Anglais. Vous pouvez également afficher le texte anglais dans une fenêtre contextuelle en faisant glisser le pointeur de la souris sur le texte traduit.
Traduction
Anglais

DataGridView.ColumnHeadersHeightSizeMode propriété

 

Date de publication : novembre 2016

Obtient ou définit une valeur indiquant si la hauteur des en-têtes de colonnes est réglable et si elle peut être ajustée par l'utilisateur ou si elle est automatiquement ajustée pour correspondre au contenu des en-têtes.

Espace de noms:   System.Windows.Forms
Assembly:  System.Windows.Forms (dans System.Windows.Forms.dll)

public DataGridViewColumnHeadersHeightSizeMode ColumnHeadersHeightSizeMode { get; set; }

Valeur de propriété

Type: System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode

Valeur DataGridViewColumnHeadersHeightSizeMode indiquant le mode par lequel la hauteur de la ligne d'en-tête de colonne peut être ajustée. La valeur par défaut est EnableResizing.

Exception Condition
InvalidEnumArgumentException

La valeur spécifiée au moment de la définition de cette propriété n’est pas une valeur DataGridViewColumnHeadersHeightSizeMode valide.

When this property is set to F:System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize, the height of the column headers cannot be adjusted by the user.

To adjust the height of the column headers programmatically, use the Overload:System.Windows.Forms.DataGridView.AutoResizeColumnHeadersHeight method or set the P:System.Windows.Forms.DataGridView.ColumnHeadersHeight property.

To set the sizing mode for the row headers, use the P:System.Windows.Forms.DataGridView.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 P:System.Windows.Forms.DataGridViewCellStyle.WrapMode property value of F:System.Windows.Forms.DataGridViewTriState.True.

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

System_CAPS_noteRemarque

The T:System.Windows.Forms.DataGridView control does not support double buffering. If P:System.Windows.Forms.Control.DoubleBuffered is set to true in a derived T:System.Windows.Forms.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 T:System.Windows.Forms.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 T:System.Windows.Forms.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);
}

.NET Framework
Disponible depuis 2.0
Retour au début
Afficher: