lai

lai

  • NA
  • 1
  • 2.4k

insert word table after text

Mar 24 2011 2:32 AM
I have build a word table using wpf flow document(Visual Studio). Below is the coding. My problem is I have insert a formatted text into the richtextbox before building the table. Then, I click on the buttontable. The result I got is the table is displayed as a whole richtextbox. I cannot find the text I inserted before that. Besides that, I also cannot insert normal text after I build the table. The text will appear in the row. I have googled for a few days but got no results at all. I try to put the table in BlockUIContainer ( flowdoc1.Blocks.Add(new BlockUIContainer(table1))). But, I get an error. Can someone please help me? Thanks a lot.


 private void ToolStripButtonTable_Click(object sender, RoutedEventArgs e)
        {
            FlowDocument flowDoc1 = new FlowDocument();

            // Create the Table...
            Table table1 = new Table();
            // ...and add it to the FlowDocument Blocks collection.
            flowDoc1.Blocks.Add(table1);


            // Set some global formatting properties for the table.
            table1.CellSpacing = 10;
            table1.Background = Brushes.White;

            int numberOfColumns = 2;
            int rows = 2;
            int c;

            for (int x = 0; x < numberOfColumns; x++)
            {
                table1.Columns.Add(new TableColumn());

               for (int r = 0; r < rows; r++)
                {
                    TableRow tr = new TableRow();
                    for (c = 0; c < numberOfColumns; c++)
                    {
                        tr.Cells.Add(new TableCell(new Paragraph(new Run())));

                        if (c % 2 == 0)
                            tr.Cells[c].Background = Brushes.PapayaWhip;
                        else
                            tr.Cells[c].Background = Brushes.RoyalBlue;
                    }
                    TableRowGroup trg = new TableRowGroup();
                    trg.Rows.Add(tr);
                    table1.RowGroups.Add(trg);

                    // Set contents
                          RichTextControl.Document = flowDoc1;

                }
            }
        }


Answers (1)