DataGridViewComboBoxColumn.Items Egenskap

Definition

Hämtar samlingen med objekt som används som val i kombinationsrutorna.

public:
 property System::Windows::Forms::DataGridViewComboBoxCell::ObjectCollection ^ Items { System::Windows::Forms::DataGridViewComboBoxCell::ObjectCollection ^ get(); };
public System.Windows.Forms.DataGridViewComboBoxCell.ObjectCollection Items { get; }
member this.Items : System.Windows.Forms.DataGridViewComboBoxCell.ObjectCollection
Public ReadOnly Property Items As DataGridViewComboBoxCell.ObjectCollection

Egenskapsvärde

En DataGridViewComboBoxCell.ObjectCollection som representerar markeringen i kombinationsrutorna.

Undantag

Värdet för CellTemplate egenskapen är null.

Exempel

Följande kodexempel visar hur du använder en DataGridViewComboBoxColumn för att underlätta inmatningen TitleOfCourtesy av data i kolumnen. Egenskapen Items används för att fylla i listrutan kombinationsruta med ett urval av rubriker. Det här exemplet är en del av ett större exempel som är tillgängligt i DataGridViewComboBoxColumn avsnittet klassöversikt.

private:
    void SetAlternateChoicesUsingItems(
        DataGridViewComboBoxColumn^ comboboxColumn)
    {
        comboboxColumn->Items->AddRange("Mr.", "Ms.", "Mrs.", "Dr.");
    }

private:
    DataGridViewComboBoxColumn^ CreateComboBoxColumn()
    {
        DataGridViewComboBoxColumn^ column =
            gcnew DataGridViewComboBoxColumn();
        {
            column->DataPropertyName = ColumnName::TitleOfCourtesy.ToString();
            column->HeaderText = ColumnName::TitleOfCourtesy.ToString();
            column->DropDownWidth = 160;
            column->Width = 90;
            column->MaxDropDownItems = 3;
            column->FlatStyle = FlatStyle::Flat;
        }
        return column;
    }
private static void SetAlternateChoicesUsingItems(
    DataGridViewComboBoxColumn comboboxColumn)
{
    comboboxColumn.Items.AddRange("Mr.", "Ms.", "Mrs.", "Dr.");
}

private DataGridViewComboBoxColumn CreateComboBoxColumn()
{
    DataGridViewComboBoxColumn column =
        new DataGridViewComboBoxColumn();
    {
        column.DataPropertyName = ColumnName.TitleOfCourtesy.ToString();
        column.HeaderText = ColumnName.TitleOfCourtesy.ToString();
        column.DropDownWidth = 160;
        column.Width = 90;
        column.MaxDropDownItems = 3;
        column.FlatStyle = FlatStyle.Flat;
    }
    return column;
}
Private Shared Sub SetAlternateChoicesUsingItems( _
    ByVal comboboxColumn As DataGridViewComboBoxColumn)

    comboboxColumn.Items.AddRange("Mr.", "Ms.", "Mrs.", "Dr.")

End Sub

Private Function CreateComboBoxColumn() _
    As DataGridViewComboBoxColumn
    Dim column As New DataGridViewComboBoxColumn()

    With column
        .DataPropertyName = ColumnName.TitleOfCourtesy.ToString()
        .HeaderText = ColumnName.TitleOfCourtesy.ToString()
        .DropDownWidth = 160
        .Width = 90
        .MaxDropDownItems = 3
        .FlatStyle = FlatStyle.Flat
    End With
    Return column
End Function

Kommentarer

Den här egenskapen returnerar värdet för Items egenskapen för egenskapen DataGridViewComboBoxCell som returneras av CellTemplate egenskapen.

Egenskaperna Items eller DataSource används för att fylla i markeringarna i kombinationsrutorna.

Om strängar läggs till ItemsValueMember i behöver egenskaperna och DisplayMember inte anges eftersom varje sträng som läggs till används för både värde och visning.

Note

DataGridViewComboBoxColumn stöder inte användning av flera objekt med identiska visningsvärden.

Om egenskapen DataSource har angetts Items kan den inte användas.

Gäller för

Se även