Programmatically add rows to a Table element.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="WpfApplication1.Window1"
Title="Add Content to a Table">
<FlowDocumentScrollViewer HorizontalAlignment="Left" VerticalAlignment="Top">
<FlowDocument>
<Paragraph>
<Button Canvas.Left="5" Click="AddRow">Add a New TableRow to the Table</Button>
</Paragraph>
<Table CellSpacing="5" Name="table1">
<Table.Columns>
<TableColumn/>
</Table.Columns>
<TableRowGroup Name="trg1">
<TableRow>
<TableCell>
<Paragraph FontSize="14pt">TableRow</Paragraph>
</TableCell>
</TableRow>
</TableRowGroup>
</Table>
</FlowDocument>
</FlowDocumentScrollViewer>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Namespace WpfApplication1
Public Partial Class Window1
Inherits Window
Public Sub AddRow(sender As Object, e As RoutedEventArgs)
Dim row As New TableRow()
trg1.Rows.Add(row)
Dim para As New Paragraph()
para.Inlines.Add("A new Row and Cell have been Added to the Table")
Dim cell As New TableCell(para)
row.Cells.Add(cell)
End Sub
End Class
End Namespace
Related examples in the same category