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.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.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 에 연결 된 DataGridViewButtonCell 에서 모든 DataGridViewRow 과 교차 하는 합니다. 각 셀은 컨트롤과 유사한 UI(사용자 인터페이스)를 Button 제공합니다.

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

이 열 형식에 대 한 기본 정렬 모드 NotSortable합니다.

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

참고

비주얼 스타일을 사용하도록 설정하면 단추 열의 단추는 를 사용하여 ButtonRenderer그려지고 와 같은 DefaultCellStyle 속성을 통해 지정된 셀 스타일은 영향을 주지 않습니다.

상속자 참고

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

생성자

DataGridViewButtonColumn()

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

속성

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)

메서드

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()

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

이벤트

Disposed

DataGridViewColumn이 삭제될 때 발생합니다.

(다음에서 상속됨 DataGridViewColumn)

적용 대상

추가 정보