DataGridViewEditingControlShowingEventArgs.Control DataGridViewEditingControlShowingEventArgs.Control DataGridViewEditingControlShowingEventArgs.Control DataGridViewEditingControlShowingEventArgs.Control Property

定義

選択したセルの値を編集するためにユーザーに表示されるコントロールです。The control shown to the user for editing the selected cell's value.

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

プロパティ値

選択したセルの値をユーザーが入力または変更するための領域を表示する ControlA Control that displays an area for the user to enter or change the selected cell's value.

次のコード例は、このプロパティの使用方法を示しています。The following code example illustrates the use of this property. この例では、 DataGridView.EditingControlShowingイベントハンドラーがDataGridViewComboBoxEditingControlイベントのハンドラーを追加します。In the example, a DataGridView.EditingControlShowing event handler adds a handler for a DataGridViewComboBoxEditingControl event. 編集コントロールは、 ComboBox ComboBox.SelectedIndexChangedイベントを処理するためににキャストされます。The editing control is cast to a ComboBox to handle the ComboBox.SelectedIndexChanged event.

private DataGridView dataGridView1 = new DataGridView();

private void AddColorColumn()
{
    DataGridViewComboBoxColumn comboBoxColumn =
        new DataGridViewComboBoxColumn();
    comboBoxColumn.Items.AddRange(
        Color.Red, Color.Yellow, Color.Green, Color.Blue);
    comboBoxColumn.ValueType = typeof(Color);
    dataGridView1.Columns.Add(comboBoxColumn);
    dataGridView1.EditingControlShowing +=
        new DataGridViewEditingControlShowingEventHandler(
        dataGridView1_EditingControlShowing);
}

private void dataGridView1_EditingControlShowing(object sender,
    DataGridViewEditingControlShowingEventArgs e)
{
    ComboBox combo = e.Control as ComboBox;
    if (combo != null)
    {
        // Remove an existing event-handler, if present, to avoid 
        // adding multiple handlers when the editing control is reused.
        combo.SelectedIndexChanged -=
            new EventHandler(ComboBox_SelectedIndexChanged);

        // Add the event handler. 
        combo.SelectedIndexChanged +=
            new EventHandler(ComboBox_SelectedIndexChanged);
    }
}

private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    ((ComboBox)sender).BackColor = (Color)((ComboBox)sender).SelectedItem;
}
Private WithEvents dataGridView1 As New DataGridView()

Private Sub AddColorColumn()

    Dim comboBoxColumn As New DataGridViewComboBoxColumn()
    comboBoxColumn.Items.AddRange( _
        Color.Red, Color.Yellow, Color.Green, Color.Blue)
    comboBoxColumn.ValueType = GetType(Color)
    dataGridView1.Columns.Add(comboBoxColumn)

End Sub

Private Sub dataGridView1_EditingControlShowing(ByVal sender As Object, _
    ByVal e As DataGridViewEditingControlShowingEventArgs) _
    Handles dataGridView1.EditingControlShowing

    Dim combo As ComboBox = CType(e.Control, ComboBox)
    If (combo IsNot Nothing) Then

        ' Remove an existing event-handler, if present, to avoid 
        ' adding multiple handlers when the editing control is reused.
        RemoveHandler combo.SelectedIndexChanged, _
            New EventHandler(AddressOf ComboBox_SelectedIndexChanged)

        ' Add the event handler. 
        AddHandler combo.SelectedIndexChanged, _
            New EventHandler(AddressOf ComboBox_SelectedIndexChanged)

    End If

End Sub

Private Sub ComboBox_SelectedIndexChanged( _
    ByVal sender As Object, ByVal e As EventArgs)

    Dim comboBox1 As ComboBox = CType(sender, ComboBox)
    comboBox1.BackColor = _
        CType(CType(sender, ComboBox).SelectedItem, Color)

End Sub

注釈

コントロールの表示特性をカスタマイズするには、プロパティによっCellStyle Controlて返されるコントロールのプロパティを設定するのではなく、プロパティによって返されるオブジェクトのプロパティを設定します。To customize the display characteristics of the control, set the properties of the object returned by the CellStyle property rather than setting the properties of the control returned by the Control property.

適用対象

こちらもご覧ください