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.ColumnHeadersBorderStyle propriété

 

Date de publication : novembre 2016

Obtient le style de bordure appliqué aux en-têtes de colonnes.

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

[BrowsableAttribute(true)]
public DataGridViewHeaderBorderStyle ColumnHeadersBorderStyle { get; set; }

Exception Condition
InvalidEnumArgumentException

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

ArgumentException

La valeur spécifiée lors de la définition de cette propriété est Custom.

If the P:System.Windows.Forms.DataGridView.ColumnHeadersBorderStyle property is set to anything other than F:System.Windows.Forms.DataGridViewHeaderBorderStyle.Single, the P:System.Windows.Forms.DataGridView.GridColor property must be a system color.

You cannot set this property to the F:System.Windows.Forms.DataGridViewHeaderBorderStyle.Custom value, which is a read-only value indicating that the border style has been customized through the use of the P:System.Windows.Forms.DataGridView.AdvancedColumnHeadersBorderStyle property.

System_CAPS_noteRemarque

If visual styles are enabled for the application through the M:System.Windows.Forms.Application.EnableVisualStyles method and the P:System.Windows.Forms.DataGridView.EnableHeadersVisualStyles property is true, the column headers are painted using the current theme. In this case, the value of the P:System.Windows.Forms.DataGridView.ColumnHeadersBorderStyle property is ignored for all column headers except the P:System.Windows.Forms.DataGridView.TopLeftHeaderCell, to which the theme is not applied.

The following code example demonstrates how to set the P:System.Windows.Forms.DataGridView.ColumnHeadersDefaultCellStyle, P:System.Windows.Forms.DataGridView.AutoSizeRowsMode, P:System.Windows.Forms.DataGridView.ColumnHeadersBorderStyle, P:System.Windows.Forms.DataGridView.CellBorderStyle, P:System.Windows.Forms.DataGridView.GridColor, P:System.Windows.Forms.DataGridView.BackgroundColor, P:System.Windows.Forms.DataGridView.RowHeadersVisible, P:System.Windows.Forms.DataGridView.SelectionMode, P:System.Windows.Forms.DataGridView.ColumnCount, and P:System.Windows.Forms.DataGridView.MultiSelect properties. In addition, the code example demonstrates how to set the P:System.Windows.Forms.DataGridViewColumn.Name and P:System.Windows.Forms.DataGridViewColumn.DefaultCellStyle properties. To run this example, paste the code into a form that contains a T:System.Windows.Forms.DataGridView nameddataGridView1, and then call the SetUpDataGridView method from the form's constructor or E:System.Windows.Forms.Form.Load event handler. Ensure all events are associated with their event handlers.

private void SetUpDataGridView()
{
    this.Controls.Add(dataGridView1);
    dataGridView1.ColumnCount = 5;
    DataGridViewCellStyle style = 
        dataGridView1.ColumnHeadersDefaultCellStyle;
    style.BackColor = Color.Navy;
    style.ForeColor = Color.White;
    style.Font = new Font(dataGridView1.Font, FontStyle.Bold);

    dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
    dataGridView1.Name = "dataGridView1";
    dataGridView1.Location = new Point(8, 8);
    dataGridView1.Size = new Size(500, 300);
    dataGridView1.AutoSizeRowsMode = 
        DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
    dataGridView1.ColumnHeadersBorderStyle = 
        DataGridViewHeaderBorderStyle.Raised;
    dataGridView1.CellBorderStyle = DataGridViewCellBorderStyle.Single;
    dataGridView1.GridColor = SystemColors.ActiveBorder;
    dataGridView1.RowHeadersVisible = false;

    dataGridView1.Columns[0].Name = "Release Date";
    dataGridView1.Columns[1].Name = "Track";
    dataGridView1.Columns[1].DefaultCellStyle.Alignment = 
        DataGridViewContentAlignment.MiddleCenter;
    dataGridView1.Columns[2].Name = "Title";
    dataGridView1.Columns[3].Name = "Artist";
    dataGridView1.Columns[4].Name = "Album";

    // Make the font italic for row four.
    dataGridView1.Columns[4].DefaultCellStyle.Font = new Font(DataGridView.DefaultFont, FontStyle.Italic);

    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
    dataGridView1.MultiSelect = false;

    dataGridView1.BackgroundColor = Color.Honeydew;

    dataGridView1.Dock = DockStyle.Fill;

    dataGridView1.CellFormatting += new DataGridViewCellFormattingEventHandler(dataGridView1_CellFormatting);
    dataGridView1.CellParsing += new DataGridViewCellParsingEventHandler(dataGridView1_CellParsing);
    addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
    deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
    ledgerStyleButton.Click += new EventHandler(ledgerStyleButton_Click);
    dataGridView1.CellValidating += new DataGridViewCellValidatingEventHandler(dataGridView1_CellValidating);

}

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