DataGridViewColumn.Name Property


열 이름을 가져오거나 설정합니다.Gets or sets the name of the column.

 property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String

Property Value


열의 이름을 포함하는 String입니다.A String that contains the name of the column. 기본값은 빈 문자열("")입니다.The default is an empty string ("").



다음 코드 예제에는 열 이름을 설정 하는 방법을 보여 줍니다.The following code example shows how to set the column name.

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


이 속성은 컬렉션의 열을 식별 하는 열에 연결 된 형식 이름을 나타냅니다.This property represents a formal name associated with the column that can be used to identify the column in a collection. 예를 들어 DataGridViewColumnCollection 클래스의 RemoveContains 메서드는 Name 속성을 사용 합니다.For example, the Remove and Contains methods of the DataGridViewColumnCollection class use the Name property. 이름은 대/소문자입니다.The name is case-insensitive. DataGridViewcolumn1COLUMN1을 동일한 열로 처리 합니다.The DataGridView will treat column1 and COLUMN1 as the same column.

Applies to

See also