DataGridViewColumn.DataPropertyName 속성


DataGridViewColumn이 바인딩되는 데이터베이스 열이나 데이터 소스 속성의 이름을 가져오거나 설정합니다.Gets or sets the name of the data source property or database column to which the DataGridViewColumn is bound.

 property System::String ^ DataPropertyName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Windows.Forms.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string DataPropertyName { get; set; }
member this.DataPropertyName : string with get, set
Public Property DataPropertyName As String

속성 값

DataGridViewColumn과 연결된 데이터베이스 열이나 속성의 이름(대/소문자를 구분하지 않음)입니다.The case-insensitive name of the property or database column associated with the DataGridViewColumn.



다음 코드 예제에는 각 열이 나타내는 속성을 선택 하는 방법을 보여 줍니다.The following code example shows how to choose what property each column will represent.

public enum Title
Public Enum Title
End Enum
private void EnumsAndComboBox_Load(object sender, System.EventArgs e)
    // Populate the data source.
    bindingSource1.Add(new Knight(Title.King, "Uther", true));
    bindingSource1.Add(new Knight(Title.King, "Arthur", true));
    bindingSource1.Add(new Knight(Title.Sir, "Mordred", false));
    bindingSource1.Add(new Knight(Title.Sir, "Gawain", true));
    bindingSource1.Add(new Knight(Title.Sir, "Galahad", true));

    // Initialize the DataGridView.
    dataGridView1.AutoGenerateColumns = false;
    dataGridView1.AutoSize = true;
    dataGridView1.DataSource = bindingSource1;


    // Initialize and add a text box column.
    DataGridViewColumn column = new DataGridViewTextBoxColumn();
    column.DataPropertyName = "Name";
    column.Name = "Knight";

    // Initialize and add a check box column.
    column = new DataGridViewCheckBoxColumn();
    column.DataPropertyName = "GoodGuy";
    column.Name = "Good";

    // Initialize the form.
    this.AutoSize = true;
    this.Text = "DataGridView object binding demo";

DataGridViewComboBoxColumn CreateComboBoxWithEnums()
    DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
    combo.DataSource = Enum.GetValues(typeof(Title));
    combo.DataPropertyName = "Title";
    combo.Name = "Title";
    return combo;
#region "business object"
private class Knight
    private string hisName;
    private bool good;
    private Title hisTitle;

    public Knight(Title title, string name, bool good)
        hisTitle = title;
        hisName = name;
        this.good = good;

    public Knight()
        hisTitle = Title.Sir;
        hisName = "<enter name>";
        good = true;

    public string Name
            return hisName;

            hisName = value;

    public bool GoodGuy
            return good;
            good = value;

    public Title Title
            return hisTitle;
            hisTitle = value;
    Private Sub SetupGrid()
        knights = New List(Of Knight)
        knights.Add(New Knight(Title.King, "Uther", True))
        knights.Add(New Knight(Title.King, "Arthur", True))
        knights.Add(New Knight(Title.Sir, "Mordred", False))
        knights.Add(New Knight(Title.Sir, "Gawain", True))
        knights.Add(New Knight(Title.Sir, "Galahad", True))

        ' Initialize the DataGridView.
        dataGridView1.AutoGenerateColumns = False
        dataGridView1.AutoSize = True
        dataGridView1.DataSource = knights


        ' Initialize and add a text box column.
        Dim column As DataGridViewColumn = _
            New DataGridViewTextBoxColumn()
        column.DataPropertyName = "Name"
        column.Name = "Knight"

        ' Initialize and add a check box column.
        column = New DataGridViewCheckBoxColumn()
        column.DataPropertyName = "GoodGuy"
        column.Name = "Good"

        ' Initialize the form.
        Me.AutoSize = True
        Me.Text = "DataGridView object binding demo"
    End Sub

    Private Function CreateComboBoxWithEnums() As DataGridViewComboBoxColumn
        Dim combo As New DataGridViewComboBoxColumn()
        combo.DataSource = [Enum].GetValues(GetType(Title))
        combo.DataPropertyName = "Title"
        combo.Name = "Title"
        Return combo
    End Function

#Region "business object"
    Private Class Knight
        Private hisName As String
        Private good As Boolean
        Private hisTitle As Title

        Public Sub New(ByVal title As Title, ByVal name As String, _
            ByVal good As Boolean)

            hisTitle = title
            hisName = name
            Me.good = good
        End Sub

        Public Property Name() As String
                Return hisName
            End Get

            Set(ByVal Value As String)
                hisName = Value
            End Set
        End Property

        Public Property GoodGuy() As Boolean
                Return good
            End Get
            Set(ByVal Value As Boolean)
                good = Value
            End Set
        End Property

        Public Property Title() As Title
                Return hisTitle
            End Get
            Set(ByVal Value As Title)
                hisTitle = Value
            End Set
        End Property
    End Class
#End Region


경우는 AutoGenerateColumns 속성이로 설정 되어 true, 각 열을 자동으로 설정 해당 DataPropertyName 속성에서 지정 된 데이터 소스의 속성 또는 데이터베이스 열 이름으로는 DataSource 속성입니다.When the AutoGenerateColumns property is set to true, each column automatically sets its DataPropertyName property to the name of a property or database column in the data source specified by the DataSource property. 이 바인딩을 수행할 수도 있습니다 수동으로 데이터 원본에 사용할 수 있는 데이터베이스 열 또는 속성의 하위 집합만 표시 하려는 경우에 유용 합니다.This binding can also be performed manually, which is useful when you want to display only a subset of the properties or database columns available in the data source. 이러한 경우에 설정 합니다 AutoGenerateColumns 속성을 false를 추가한 다음 수동으로 각 DataGridViewColumn, 각각의 값을 설정 DataPropertyName 속성을 표시 하려는 데이터 원본에 데이터베이스 열 또는 속성을 합니다.In such cases, set the AutoGenerateColumns property to false, and then manually add each DataGridViewColumn, setting the value of each DataPropertyName property to the properties or database columns in the data source that you want to display.

적용 대상

추가 정보