방법: RowGroups 속성을 통한 표의 행 그룹 조작

이 예제에서는 RowGroups 속성을 통해 테이블의 행 그룹에서 수행할 수 있는 더 일반적인 작업 중 일부를 설명합니다.

Add 메서드를 사용하여 새 테이블 만들기

다음 예제에서는 새 테이블을 만든 다음, Add 메서드를 사용하여 테이블의 RowGroups 컬렉션에 열을 추가합니다.

Table tbl = new Table();
int rowGroupsToAdd = 4;
for (int x = 0; x < rowGroupsToAdd; x++)
    tbl.RowGroups.Add(new TableRowGroup());
Dim tbl As New Table()
Dim rowGroupsToAdd As Integer = 4
For x As Integer = 0 To rowGroupsToAdd - 1
    tbl.RowGroups.Add(New TableRowGroup())
Next x

새 TableRowGroup 삽입

다음 예제에서는 새 TableRowGroup을 삽입합니다. 새 열은 인덱스 위치 0에 삽입되어 테이블의 새로운 첫 번째 행 그룹이 되었습니다.

참고

TableRowGroupCollection 컬렉션은 표준 0부터 시작하는 인덱싱을 사용합니다.

tbl.RowGroups.Insert(0, new TableRowGroup());
tbl.RowGroups.Insert(0, New TableRowGroup())

TableRowGroup에 행 추가

다음 예제에서는 테이블의 특정 TableRowGroup(인덱스로 지정됨)에 여러 행을 추가합니다.

int rowsToAdd = 10;
for (int x = 0; x < rowsToAdd; x++)
    tbl.RowGroups[0].Rows.Add(new TableRow());
Dim rowsToAdd As Integer = 10
For x As Integer = 0 To rowsToAdd - 1
    tbl.RowGroups(0).Rows.Add(New TableRow())
Next x

첫 번째 행 그룹의 행 속성에 액세스

다음 예제에서는 테이블의 첫 번째 행 그룹에 있는 행의 일부 임의 속성에 액세스합니다.

// Alias the working TableRowGroup for ease in referencing.
TableRowGroup trg = tbl.RowGroups[0];
trg.Rows[0].Background = Brushes.CornflowerBlue;
trg.Rows[1].FontSize = 24;
trg.Rows[2].ToolTip = "This row's tooltip";
' Alias the working TableRowGroup for ease in referencing.
Dim trg As TableRowGroup = tbl.RowGroups(0)
trg.Rows(0).Background = Brushes.CornflowerBlue
trg.Rows(1).FontSize = 24
trg.Rows(2).ToolTip = "This row's tooltip"

TableRow에 셀 추가

다음 예제에서는 표의 특정 TableRow(인덱스로 지정됨)에 여러 셀을 추가합니다.

int cellsToAdd = 10;
for (int x = 0; x < cellsToAdd; x++)
    tbl.RowGroups[0].Rows[0].Cells.Add(new TableCell(new Paragraph(new Run("Cell " + (x + 1)))));
Dim cellsToAdd As Integer = 10
For x As Integer = 0 To cellsToAdd - 1
    tbl.RowGroups(0).Rows(0).Cells.Add(New TableCell(New Paragraph(New Run("Cell " & (x + 1)))))
Next x

첫 번째 행 그룹의 셀에 대한 메서드 및 속성 액세스

다음 예제에서는 첫 번째 행 그룹의 첫 번째 행에 있는 셀의 일부 임의 메서드 및 속성에 액세스합니다.

// Alias the working for for ease in referencing.
TableRow row = tbl.RowGroups[0].Rows[0];
row.Cells[0].Background = Brushes.PapayaWhip;
row.Cells[1].FontStyle = FontStyles.Italic;
// This call clears all of the content from this cell.
row.Cells[2].Blocks.Clear();
' Alias the working for for ease in referencing.
Dim row As TableRow = tbl.RowGroups(0).Rows(0)
row.Cells(0).Background = Brushes.PapayaWhip
row.Cells(1).FontStyle = FontStyles.Italic
' This call clears all of the content from this cell.
row.Cells(2).Blocks.Clear()

테이블의 TableRowGroup 요소의 수 가져오기

다음 예제에서는 테이블에 호스트된 TableRowGroup 요소의 수를 반환합니다.

int rowGroups = tbl.RowGroups.Count;
Dim rowGroups As Integer = tbl.RowGroups.Count

참조로 행 그룹 제거

다음 예제에서는 참조로 특정 행 그룹을 제거합니다.

tbl.RowGroups.Remove(tbl.RowGroups[0]);
tbl.RowGroups.Remove(tbl.RowGroups(0))

인덱스별로 행 그룹 제거

다음 예제에서는 인덱스별로 특정 행 그룹을 제거합니다.

tbl.RowGroups.RemoveAt(0);
tbl.RowGroups.RemoveAt(0)

테이블의 행 그룹 컬렉션에서 모든 행 그룹 제거

다음 예제에서는 테이블의 행 그룹 컬렉션에서 모든 행 그룹을 제거합니다.

tbl.RowGroups.Clear();
tbl.RowGroups.Clear()

참고 항목