다음을 통해 공유


방법: 데이터 바인딩된 Windows Forms DataGridView 컨트롤에 바인딩되지 않은 열 추가

업데이트: 2007년 11월

DataGridView 컨트롤에 표시되는 데이터는 일반적으로 데이터 원본에서 가져온 것이지만 데이터 원본에서 가져오지 않은 데이터 열을 표시할 수도 있습니다. 이러한 종류의 열을 바인딩되지 않은 열이라고 합니다. 바인딩되지 않은 열은 여러 가지 형태일 수 있으며 주로 데이터 행의 세부 사항에 대한 액세스를 제공하는 데 사용됩니다.

다음 코드 예제에서는 마스터/세부 사항 시나리오를 구현할 때 부모 테이블의 특정 행과 관련된 자식 테이블을 표시하는 자세히 단추의 바인딩되지 않은 열을 만드는 방법을 보여 줍니다. 단추 클릭에 응답하려면 자식 테이블이 포함된 폼을 표시하는 DataGridView.CellClick 이벤트 처리기를 구현합니다.

Visual Studio에서는 이 작업을 지원합니다.

예제

Private Sub CreateUnboundButtonColumn()

    ' Initialize the button column.
    Dim buttonColumn As New DataGridViewButtonColumn

    With buttonColumn
        .HeaderText = "Details"
        .Name = "Details"
        .Text = "View Details"

        ' Use the Text property for the button text for all cells rather
        ' than using each cell's value as the text for its own button.
        .UseColumnTextForButtonValue = True
    End With

    ' Add the button column to the control.
    dataGridView1.Columns.Insert(1, buttonColumn)

End Sub
private void CreateUnboundButtonColumn()
{
    // Initialize the button column.
    DataGridViewButtonColumn buttonColumn =
        new DataGridViewButtonColumn();
    buttonColumn.Name = "Details";
    buttonColumn.HeaderText = "Details";
    buttonColumn.Text = "View Details";

    // Use the Text property for the button text for all cells rather
    // than using each cell's value as the text for its own button.
    buttonColumn.UseColumnTextForButtonValue = true;

    // Add the button column to the control.
    dataGridView1.Columns.Insert(1, buttonColumn);
}

코드 컴파일

이 예제에는 다음 사항이 필요합니다.

참고 항목

개념

Windows Forms DataGridView 컨트롤의 데이터 디스플레이 모드

참조

DataGridView

기타 리소스

Windows Forms DataGridView 컨트롤에서 데이터 표시