0

FlowDocumentScrollViewer inside this control i used Table and rows,But I want dynamically rows in run time and also when i click enter Key then save records into database and one new row add in this table.

Q (1)Is It Possible...?

if Yes Then Please help.

code here:

                                </TableCell>
                            </TableRow>                               
                            <TableRow>
                                <TableCell>
                                    <Paragraph>F9,F1 P.R.C</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>O.A No</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>O.A SI</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Heat No</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Pour Date</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Grade</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Product</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>W.I.P</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Heat Treat</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Final Clearance</Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>Fett</Paragraph>
                                </TableCell>
                            </TableRow>
                            <TableRow>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="100"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="100"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="50"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="100"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="100"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="100"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="100"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="50"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="30"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="30"></TextBox>
                                    </Paragraph>
                                </TableCell>
                                <TableCell>
                                    <Paragraph>
                                        <TextBox Width="30"></TextBox>
                                    </Paragraph>
                                </TableCell>
                            </TableRow>
                        </TableRowGroup>
                    </Table>
                </FlowDocument>
            </FlowDocumentScrollViewer>

Please See Image Of my Code OutPut:

1 Answer 1

5

I demonstrated how you can add rows to a table row with a simple application. First we need some xaml code:

<Window
    x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:WpfApplication1"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="525"
    Height="350"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <FlowDocumentScrollViewer>
            <FlowDocument>
                <Table Name="tblDummyData">
                    <TableRowGroup>
                        <TableRow>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="1.1" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="1.2" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="1.3" />
                                </Paragraph>
                            </TableCell>
                        </TableRow>
                        <TableRow>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="2.1" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="2.2" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="2.3" />
                                </Paragraph>
                            </TableCell>
                        </TableRow>
                        <TableRow>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="3.1" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="3.2" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="3.3" />
                                </Paragraph>
                            </TableCell>
                        </TableRow>
                        <TableRow>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="4.1" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="4.2" />
                                </Paragraph>
                            </TableCell>
                            <TableCell>
                                <Paragraph>
                                    <TextBlock Text="4.3" />
                                </Paragraph>
                            </TableCell>
                        </TableRow>
                    </TableRowGroup>
                </Table>
            </FlowDocument>
        </FlowDocumentScrollViewer>

        <Button Content="Add" Click="Button_Click" Grid.Row="1" />
    </Grid>
</Window>

As you can see nothing special here, just a table with bunch of rows and cells and a button for adding rows.

So here is what lays behind this code:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        var rowGroup = tblDummyData.RowGroups.FirstOrDefault();

        if (rowGroup != null)
        {
            TableRow row = new TableRow();

            TableCell cell = new TableCell();

            cell.Blocks.Add(new Paragraph(new Run("New Cell 1")));
            row.Cells.Add(cell);

            cell = new TableCell();
            cell.Blocks.Add(new Paragraph(new Run("New cell 2")));
            row.Cells.Add(cell);

            cell = new TableCell();
            cell.Blocks.Add(new Paragraph(new Run("New cell 3")));
            row.Cells.Add(cell);

            rowGroup.Rows.Add(row);
        }
    }

Here you can see how to define a table Row than populate it with as much cells as you need and append it to your row group. In my case I have only one row group but you can query them with linq and get whichewer row group you need.

Hope that helps.

Sign up to request clarification or add additional context in comments.

1 Comment

How can I add Textbox using Button_Click please. Like instead of "New cell 1" I want to add TextBox

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.