DataGridViewColumn.ValueType 속성

정의

열의 셀 값에 대한 데이터 형식을 가져오거나 설정합니다.Gets or sets the data type of the values in the column's cells.

public:
 property Type ^ ValueType { Type ^ get(); void set(Type ^ value); };
[System.ComponentModel.Browsable(false)]
public Type ValueType { get; set; }
member this.ValueType : Type with get, set
Public Property ValueType As Type

속성 값

열의 셀에 저장되는 값의 런타임 클래스를 설명하는 Type입니다.A Type that describes the run-time class of the values stored in the column's cells.

특성

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ValueType 초기화에서 속성을 DataGridViewComboBoxColumn 포함 하는 Color 값입니다.The following code example demonstrates how to use the ValueType property in the initialization of a DataGridViewComboBoxColumn that contains Color values.

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

설명

이 속성에는 필터링 하거나 해당 셀의 내용에 대해 열을 정렬할 때 사용 됩니다.This property is used when filtering or sorting the columns with respect to the contents of their cells.

적용 대상

추가 정보