DataGridViewEditingControlShowingEventArgs.Control 속성

정의

선택된 셀 값을 편집하기 위해 사용자에게 표시되는 컨트롤입니다.

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

속성 값

사용자가 선택된 셀 값을 입력하거나 변경하기 위한 영역을 표시하는 Control입니다.

예제

다음 코드 예제에서는이 속성의 사용을 보여 줍니다. 예에서를 DataGridView.EditingControlShowing 에 대 한 처리기를 추가 하는 이벤트 처리기는 DataGridViewComboBoxEditingControl 이벤트입니다. 편집 컨트롤으로 캐스팅 되는 ComboBox 처리 하는 ComboBox.SelectedIndexChanged 이벤트.

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 속성입니다.

적용 대상

추가 정보