Compartir a través de


Cómo: Manipular grupos de filas de una tabla mediante la propiedad RowGroups

En este ejemplo se muestran algunas de las operaciones más comunes que se pueden realizar en los grupos de filas de una tabla mediante la propiedad RowGroups.

Ejemplo

En el ejemplo siguiente se crea una nueva tabla y, a continuación, se utiliza el método Add para agregar columnas a la colección RowGroups de la tabla.

            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
Table tbl = new Table();
int rowGroupsToAdd = 4;
for (int x = 0; x < rowGroupsToAdd; x++)
    tbl.RowGroups.Add(new TableRowGroup());

En el ejemplo siguiente se inserta un nuevo objeto TableRowGroup. La nueva columna se inserta en la posición de índice 0, lo que la convierte en el primer grupo de filas de la tabla.

NotaNota

La colección TableRowGroupCollection utiliza la indización estándar basada en cero.

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

En el ejemplo siguiente se agregan varias filas a un objeto TableRowGroup determinado (especificado por su índice) de la tabla.

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

En el ejemplo siguiente se tiene acceso a algunas propiedades arbitrarias de las filas del primer grupo de filas de la tabla.

            ' 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"
// 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";

En el ejemplo siguiente se agregan varias celdas a un objeto TableRow determinado (especificado por su índice) de la tabla.

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

En el ejemplo siguiente se tiene acceso a algunos métodos y propiedades arbitrarios de las celdas de la primera fila del primer grupo de filas.

            ' 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()
// 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();

En el ejemplo siguiente se devuelve el número de elementos TableRowGroup hospedados por la tabla.

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

En el ejemplo siguiente se quita un grupo de filas en particular por su referencia.

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

En el ejemplo siguiente se quita un grupo de filas en particular por su índice.

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

En el ejemplo siguiente se quitan todos los grupos de filas de la colección de grupos de filas de la tabla.

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

Vea también

Tareas

Cómo: Manipular grupos de filas de una tabla mediante la propiedad RowGroups

Cómo: Manipular un objeto FlowDocument mediante la propiedad Blocks

Cómo: Manipular las columnas de una tabla mediante la propiedad Columns