Partager via


DataGridViewColumnCollection.Insert(Int32, DataGridViewColumn) Méthode

Définition

Insère une colonne à l'index donné dans la collection.

public:
 virtual void Insert(int columnIndex, System::Windows::Forms::DataGridViewColumn ^ dataGridViewColumn);
public virtual void Insert (int columnIndex, System.Windows.Forms.DataGridViewColumn dataGridViewColumn);
abstract member Insert : int * System.Windows.Forms.DataGridViewColumn -> unit
override this.Insert : int * System.Windows.Forms.DataGridViewColumn -> unit
Public Overridable Sub Insert (columnIndex As Integer, dataGridViewColumn As DataGridViewColumn)

Paramètres

columnIndex
Int32

Index de base zéro au niveau duquel insérer la colonne donnée.

dataGridViewColumn
DataGridViewColumn

DataGridViewColumn à insérer.

Exceptions

dataGridViewColumn a la valeur null.

Le contrôle DataGridView associé exécute l'une des opérations suivantes qui empêchent temporairement l'ajout de nouvelles colonnes :

Exemples

L’exemple de code suivant illustre l’utilisation de cette méthode. Pour plus d’informations, consultez How to: Add an Unbound Column to a Data-Bound Windows Forms DataGridView Control.

private void CreateUnboundButtonColumn()
{
    // Initialize the button column.
    DataGridViewButtonColumn buttonColumn =
        new DataGridViewButtonColumn();
    buttonColumn.Name = "Details";
    buttonColumn.HeaderText = "Details";
    buttonColumn.Text = "View Details";

    // Use the Text property for the button text for all cells rather
    // than using each cell's value as the text for its own button.
    buttonColumn.UseColumnTextForButtonValue = true;

    // Add the button column to the control.
    dataGridView1.Columns.Insert(0, buttonColumn);
}
Private Sub CreateUnboundButtonColumn()

    ' Initialize the button column.
    Dim buttonColumn As New DataGridViewButtonColumn

    With buttonColumn
        .HeaderText = "Details"
        .Name = "Details"
        .Text = "View Details"

        ' Use the Text property for the button text for all cells rather
        ' than using each cell's value as the text for its own button.
        .UseColumnTextForButtonValue = True
    End With

    ' Add the button column to the control.
    dataGridView1.Columns.Insert(0, buttonColumn)

End Sub

S’applique à

Voir aussi