Share via


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

DataGridView 컨트롤에서 표시하는 데이터는 대개 일종의 데이터 소스에서 가져오지만 데이터 소스에서 가져오지 않는 데이터 열을 표시할 수 있습니다. 이 열 유형을 바인딩되지 않은 열이라고 합니다. 바인딩되지 않은 열에서는 대부분 폼을 사용할 수 있습니다. 대부분 경우에 바인딩되지 않은 열은 데이터 행의 세부 정보에 액세스하는 데 사용됩니다.

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

Visual Studio에서는 이 작업이 지원됩니다. 방법: 디자이너를 사용하여 Windows Forms DataGridView 컨트롤에서 열 추가 및 제거도 참조하세요.

예제

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(0, buttonColumn);
}
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(0, buttonColumn)

End Sub

코드 컴파일

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

참고 항목