다음을 통해 공유


DataGridViewButtonColumn 클래스

정의

개체 컬렉션을 DataGridViewButtonCell 호스팅합니다.

public ref class DataGridViewButtonColumn : System::Windows::Forms::DataGridViewColumn
[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewButtonColumn), "DataGridViewButtonColumn.bmp")]
public class DataGridViewButtonColumn : System.Windows.Forms.DataGridViewColumn
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewButtonColumn), "DataGridViewButtonColumn")]
public class DataGridViewButtonColumn : System.Windows.Forms.DataGridViewColumn
[System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewButtonColumn), "DataGridViewButtonColumn")]
public class DataGridViewButtonColumn : System.Windows.Forms.DataGridViewColumn
[<System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewButtonColumn), "DataGridViewButtonColumn.bmp")>]
type DataGridViewButtonColumn = class
    inherit DataGridViewColumn
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)>]
[<System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewButtonColumn), "DataGridViewButtonColumn")>]
type DataGridViewButtonColumn = class
    inherit DataGridViewColumn
[<System.Drawing.ToolboxBitmap(typeof(System.Windows.Forms.DataGridViewButtonColumn), "DataGridViewButtonColumn")>]
type DataGridViewButtonColumn = class
    inherit DataGridViewColumn
Public Class DataGridViewButtonColumn
Inherits DataGridViewColumn
상속
특성

예제

다음 코드 예제에서는 특정 행에 대 한 DataGridViewButtonColumn 작업을 수행 하는 데 사용 하는 방법을 보여 줍니다. 이 예제 DataGridView.CellClick 에서 이벤트 처리기는 먼저 클릭이 단추 셀에 있는지 여부를 확인한 다음 행과 연결된 비즈니스 개체를 검색합니다. 이 예제는 방법: Windows Forms DataGridViewComboBoxCell Drop-Down 목록의 개체 액세스에서 사용할 수 있는 더 큰 예제의 일부입니다.

public class Form1 : Form
{
    private List<Employee> employees = new List<Employee>();
    private List<Task> tasks = new List<Task>();
    private Button reportButton = new Button();
    private DataGridView dataGridView1 = new DataGridView();

    [STAThread]
    public static void Main()
    {
        Application.Run(new Form1());
    }

    public Form1()
    {
        dataGridView1.Dock = DockStyle.Fill;
        dataGridView1.AutoSizeColumnsMode = 
            DataGridViewAutoSizeColumnsMode.AllCells;
        reportButton.Text = "Generate Report";
        reportButton.Dock = DockStyle.Top;
        reportButton.Click += new EventHandler(reportButton_Click);

        Controls.Add(dataGridView1);
        Controls.Add(reportButton);
        Load += new EventHandler(Form1_Load);
        Text = "DataGridViewComboBoxColumn Demo";
    }

    // Initializes the data source and populates the DataGridView control.
    private void Form1_Load(object sender, EventArgs e)
    {
        PopulateLists();
        dataGridView1.AutoGenerateColumns = false;
        dataGridView1.DataSource = tasks;
        AddColumns();
    }

    // Populates the employees and tasks lists. 
    private void PopulateLists()
    {
        employees.Add(new Employee("Harry"));
        employees.Add(new Employee("Sally"));
        employees.Add(new Employee("Roy"));
        employees.Add(new Employee("Pris"));
        tasks.Add(new Task(1, employees[1]));
        tasks.Add(new Task(2));
        tasks.Add(new Task(3, employees[2]));
        tasks.Add(new Task(4));
    }

    // Configures columns for the DataGridView control.
    private void AddColumns()
    {
        DataGridViewTextBoxColumn idColumn = 
            new DataGridViewTextBoxColumn();
        idColumn.Name = "Task";
        idColumn.DataPropertyName = "Id";
        idColumn.ReadOnly = true;

        DataGridViewComboBoxColumn assignedToColumn = 
            new DataGridViewComboBoxColumn();

        // Populate the combo box drop-down list with Employee objects. 
        foreach (Employee e in employees) assignedToColumn.Items.Add(e);

        // Add "unassigned" to the drop-down list and display it for 
        // empty AssignedTo values or when the user presses CTRL+0. 
        assignedToColumn.Items.Add("unassigned");
        assignedToColumn.DefaultCellStyle.NullValue = "unassigned";

        assignedToColumn.Name = "Assigned To";
        assignedToColumn.DataPropertyName = "AssignedTo";
        assignedToColumn.AutoComplete = true;
        assignedToColumn.DisplayMember = "Name";
        assignedToColumn.ValueMember = "Self";

        // Add a button column. 
        DataGridViewButtonColumn buttonColumn = 
            new DataGridViewButtonColumn();
        buttonColumn.HeaderText = "";
        buttonColumn.Name = "Status Request";
        buttonColumn.Text = "Request Status";
        buttonColumn.UseColumnTextForButtonValue = true;

        dataGridView1.Columns.Add(idColumn);
        dataGridView1.Columns.Add(assignedToColumn);
        dataGridView1.Columns.Add(buttonColumn);

        // Add a CellClick handler to handle clicks in the button column.
        dataGridView1.CellClick +=
            new DataGridViewCellEventHandler(dataGridView1_CellClick);
    }

    // Reports on task assignments. 
    private void reportButton_Click(object sender, EventArgs e)
    {
        StringBuilder report = new StringBuilder();
        foreach (Task t in tasks)
        {
            String assignment = 
                t.AssignedTo == null ? 
                "unassigned" : "assigned to " + t.AssignedTo.Name;
            report.AppendFormat("Task {0} is {1}.", t.Id, assignment);
            report.Append(Environment.NewLine);
        }
        MessageBox.Show(report.ToString(), "Task Assignments");
    }

    // Calls the Employee.RequestStatus method.
    void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        // Ignore clicks that are not on button cells. 
        if (e.RowIndex < 0 || e.ColumnIndex !=
            dataGridView1.Columns["Status Request"].Index) return;

        // Retrieve the task ID.
        Int32 taskID = (Int32)dataGridView1[0, e.RowIndex].Value;

        // Retrieve the Employee object from the "Assigned To" cell.
        Employee assignedTo = dataGridView1.Rows[e.RowIndex]
            .Cells["Assigned To"].Value as Employee;

        // Request status through the Employee object if present. 
        if (assignedTo != null)
        {
            assignedTo.RequestStatus(taskID);
        }
        else
        {
            MessageBox.Show(String.Format(
                "Task {0} is unassigned.", taskID), "Status Request");
        }
    }
}
Public Class Form1
    Inherits Form

    Private employees As New List(Of Employee)
    Private tasks As New List(Of Task)
    Private WithEvents reportButton As New Button
    Private WithEvents dataGridView1 As New DataGridView

    <STAThread()> _
    Public Sub Main()
        Application.Run(New Form1)
    End Sub

    Sub New()
        dataGridView1.Dock = DockStyle.Fill
        dataGridView1.AutoSizeColumnsMode = _
            DataGridViewAutoSizeColumnsMode.AllCells
        reportButton.Text = "Generate Report"
        reportButton.Dock = DockStyle.Top

        Controls.Add(dataGridView1)
        Controls.Add(reportButton)
        Text = "DataGridViewComboBoxColumn Demo"
    End Sub

    ' Initializes the data source and populates the DataGridView control.
    Private Sub Form1_Load(ByVal sender As Object, _
        ByVal e As EventArgs) Handles Me.Load

        PopulateLists()
        dataGridView1.AutoGenerateColumns = False
        dataGridView1.DataSource = tasks
        AddColumns()

    End Sub

    ' Populates the employees and tasks lists. 
    Private Sub PopulateLists()
        employees.Add(New Employee("Harry"))
        employees.Add(New Employee("Sally"))
        employees.Add(New Employee("Roy"))
        employees.Add(New Employee("Pris"))
        tasks.Add(New Task(1, employees(1)))
        tasks.Add(New Task(2))
        tasks.Add(New Task(3, employees(2)))
        tasks.Add(New Task(4))
    End Sub

    ' Configures columns for the DataGridView control.
    Private Sub AddColumns()

        Dim idColumn As New DataGridViewTextBoxColumn()
        idColumn.Name = "Task"
        idColumn.DataPropertyName = "Id"
        idColumn.ReadOnly = True

        Dim assignedToColumn As New DataGridViewComboBoxColumn()

        ' Populate the combo box drop-down list with Employee objects. 
        For Each e As Employee In employees
            assignedToColumn.Items.Add(e)
        Next

        ' Add "unassigned" to the drop-down list and display it for 
        ' empty AssignedTo values or when the user presses CTRL+0. 
        assignedToColumn.Items.Add("unassigned")
        assignedToColumn.DefaultCellStyle.NullValue = "unassigned"

        assignedToColumn.Name = "Assigned To"
        assignedToColumn.DataPropertyName = "AssignedTo"
        assignedToColumn.AutoComplete = True
        assignedToColumn.DisplayMember = "Name"
        assignedToColumn.ValueMember = "Self"

        ' Add a button column. 
        Dim buttonColumn As New DataGridViewButtonColumn()
        buttonColumn.HeaderText = ""
        buttonColumn.Name = "Status Request"
        buttonColumn.Text = "Request Status"
        buttonColumn.UseColumnTextForButtonValue = True

        dataGridView1.Columns.Add(idColumn)
        dataGridView1.Columns.Add(assignedToColumn)
        dataGridView1.Columns.Add(buttonColumn)

    End Sub

    ' Reports on task assignments. 
    Private Sub reportButton_Click(ByVal sender As Object, _
        ByVal e As EventArgs) Handles reportButton.Click

        Dim report As New StringBuilder()
        For Each t As Task In tasks
            Dim assignment As String
            If t.AssignedTo Is Nothing Then
                assignment = "unassigned"
            Else
                assignment = "assigned to " + t.AssignedTo.Name
            End If
            report.AppendFormat("Task {0} is {1}.", t.Id, assignment)
            report.Append(Environment.NewLine)
        Next
        MessageBox.Show(report.ToString(), "Task Assignments")

    End Sub

    ' Calls the Employee.RequestStatus method.
    Private Sub dataGridView1_CellClick(ByVal sender As Object, _
        ByVal e As DataGridViewCellEventArgs) _
        Handles dataGridView1.CellClick

        ' Ignore clicks that are not on button cells. 
        If e.RowIndex < 0 OrElse Not e.ColumnIndex = _
            dataGridView1.Columns("Status Request").Index Then Return

        ' Retrieve the task ID.
        Dim taskID As Int32 = CInt(dataGridView1(0, e.RowIndex).Value)

        ' Retrieve the Employee object from the "Assigned To" cell.
        Dim assignedTo As Employee = TryCast(dataGridView1.Rows(e.RowIndex) _
            .Cells("Assigned To").Value, Employee)

        ' Request status through the Employee object if present. 
        If assignedTo IsNot Nothing Then
            assignedTo.RequestStatus(taskID)
        Else
            MessageBox.Show(String.Format( _
                "Task {0} is unassigned.", taskID), "Status Request")
        End If

    End Sub

End Class

설명

클래스 DataGridViewButtonColumn 는 단순 사용자 입력에 DataGridViewColumn 응답하는 셀을 논리적으로 호스트하는 데 사용되는 특수한 형식의 클래스입니다. A DataGridViewButtonColumn 는 교차하는 모든 DataGridViewRow 항목에 연결되어 DataGridViewButtonCell 있습니다. 각 셀은 컨트롤과 유사한 UI(사용자 인터페이스)를 Button 제공합니다.

모든 셀에 대해 동일한 단추 텍스트를 표시하려면 속성을 true 원하는 단추 텍스트로 설정하고 UseColumnTextForButtonValue 속성을 설정합니다Text.

이 열 형식의 기본 정렬 모드는 .입니다 NotSortable.

사용자 단추 클릭에 응답하려면 또는 DataGridView.CellContentClick 이벤트를 처리 DataGridView.CellClick 합니다. 이벤트 처리기에서 이 속성을 사용하여 DataGridViewCellEventArgs.ColumnIndex 단추 열에서 클릭이 발생했는지 여부를 확인할 수 있습니다. 이 속성을 사용하여 DataGridViewCellEventArgs.RowIndex 열 머리글이 아닌 단추 셀에서 클릭이 발생했는지 여부를 확인할 수 있습니다.

메모

비주얼 스타일을 사용하도록 설정하면 단추 열의 단추가 효과를 주지 않는 등의 DefaultCellStyle 속성을 통해 지정된 셀 스타일을 사용하여 ButtonRenderer그려집니다.

상속자 참고

파생된 클래스에서 DataGridViewButtonColumn 파생되고 새 속성을 추가하는 경우 복제 작업 중에 새 속성을 복사하도록 메서드를 재정 Clone() 의해야 합니다. 기본 클래스의 Clone() 속성이 새 셀에 복사되도록 기본 클래스의 메서드를 호출해야 합니다.

생성자

Name Description
DataGridViewButtonColumn()

클래스의 새 인스턴스를 DataGridViewButtonColumn 기본 상태로 초기화합니다.

속성

Name Description
AutoSizeMode

열이 자동으로 너비를 조정하는 모드를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
CellTemplate

새 셀을 만드는 데 사용되는 템플릿을 가져오거나 설정합니다.

CellType

셀 템플릿의 런타임 형식을 가져옵니다.

(다음에서 상속됨 DataGridViewColumn)
ContextMenuStrip

열의 바로 가기 메뉴를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
DataGridView

DataGridView 이 요소와 연결된 컨트롤을 가져옵니다.

(다음에서 상속됨 DataGridViewElement)
DataPropertyName

바인딩된 데이터 원본 속성 또는 데이터베이스 열 DataGridViewColumn 의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
DefaultCellStyle

열의 기본 셀 스타일을 가져오거나 설정합니다.

DefaultHeaderCellType

기본 헤더 셀의 런타임 형식을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewBand)
Displayed

밴드가 현재 화면에 표시되는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 DataGridViewBand)
DisplayIndex

현재 표시된 열을 기준으로 열의 표시 순서를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
DividerWidth

열 구분선의 너비(픽셀)를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
FillWeight

컨트롤에 있는 다른 채우기 모드 열의 너비를 기준으로 채우기 모드에 있을 때 열의 너비를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
FlatStyle

열에 있는 단추 셀의 평면 스타일 모양을 가져오거나 설정합니다.

Frozen

사용자가 컨트롤을 가로로 스크롤 DataGridView 할 때 열이 이동할지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
HasDefaultCellStyle

속성이 설정되었는지 여부를 DefaultCellStyle 나타내는 값을 가져옵니다.

(다음에서 상속됨 DataGridViewBand)
HeaderCell

열 머리글을 DataGridViewColumnHeaderCell 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
HeaderCellCore

의 머리글 셀을 DataGridViewBand가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewBand)
HeaderText

열의 머리글 셀에 있는 캡션 텍스트를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
Index

컨트롤 내에서 대역의 상대 위치를 가져옵니다 DataGridView .

(다음에서 상속됨 DataGridViewBand)
InheritedAutoSizeMode

열에 적용되는 크기 조정 모드를 가져옵니다.

(다음에서 상속됨 DataGridViewColumn)
InheritedStyle

열에 현재 적용된 셀 스타일을 가져옵니다.

(다음에서 상속됨 DataGridViewColumn)
IsDataBound

열이 데이터 원본에 바인딩되어 있는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 DataGridViewColumn)
IsRow

밴드가 행을 나타내는지 여부를 나타내는 값을 가져옵니다.

(다음에서 상속됨 DataGridViewBand)
MinimumWidth

열의 최소 너비(픽셀)를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
Name

열의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
ReadOnly

사용자가 열의 셀을 편집할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
Resizable

열의 크기가 조정 가능한지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
Selected

밴드가 선택한 UI(사용자 인터페이스) 상태인지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewBand)
Site

열의 사이트를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
SortMode

열의 정렬 모드를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
State

요소의 UI(사용자 인터페이스) 상태를 가져옵니다.

(다음에서 상속됨 DataGridViewElement)
Tag

밴드와 연결할 데이터가 포함된 개체를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewBand)
Text

단추 셀에 표시되는 기본 텍스트를 가져오거나 설정합니다.

ToolTipText

도구 설명에 사용되는 텍스트를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
UseColumnTextForButtonValue

속성 값이 이 열의 Text 셀에 대한 단추 텍스트로 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

ValueType

열 셀에 있는 값의 데이터 형식을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
Visible

열이 표시되는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)
Width

열의 현재 너비를 가져오거나 설정합니다.

(다음에서 상속됨 DataGridViewColumn)

메서드

Name Description
Clone()

이 열의 정확한 복사본을 만듭니다.

Dispose()

에서 사용하는 모든 리소스를 DataGridViewBand해제합니다.

(다음에서 상속됨 DataGridViewBand)
Dispose(Boolean)

관리되지 않는 리소스를 DataGridViewBand 해제하고 관리되는 리소스를 선택적으로 해제합니다.

(다음에서 상속됨 DataGridViewColumn)
Equals(Object)

지정된 개체가 현재 개체와 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 사용됩니다.

(다음에서 상속됨 Object)
GetPreferredWidth(DataGridViewAutoSizeColumnMode, Boolean)

지정된 조건에 따라 열의 이상적인 너비를 계산합니다.

(다음에서 상속됨 DataGridViewColumn)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnDataGridViewChanged()

밴드가 다른 DataGridView밴드와 연결될 때 호출됩니다.

(다음에서 상속됨 DataGridViewBand)
RaiseCellClick(DataGridViewCellEventArgs)

CellClick 이벤트를 발생시킵니다.

(다음에서 상속됨 DataGridViewElement)
RaiseCellContentClick(DataGridViewCellEventArgs)

CellContentClick 이벤트를 발생시킵니다.

(다음에서 상속됨 DataGridViewElement)
RaiseCellContentDoubleClick(DataGridViewCellEventArgs)

CellContentDoubleClick 이벤트를 발생시킵니다.

(다음에서 상속됨 DataGridViewElement)
RaiseCellValueChanged(DataGridViewCellEventArgs)

CellValueChanged 이벤트를 발생시킵니다.

(다음에서 상속됨 DataGridViewElement)
RaiseDataError(DataGridViewDataErrorEventArgs)

DataError 이벤트를 발생시킵니다.

(다음에서 상속됨 DataGridViewElement)
RaiseMouseWheel(MouseEventArgs)

MouseWheel 이벤트를 발생시킵니다.

(다음에서 상속됨 DataGridViewElement)
ToString()

열을 설명하는 문자열을 가져옵니다.

이벤트

Name Description
Disposed

삭제될 DataGridViewColumn 때 발생합니다.

(다음에서 상속됨 DataGridViewColumn)

적용 대상

추가 정보