Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

wpf c# the table is placed at the end of the richtextbox document. Can you help place the table where the cursor is in the middle of the document

$
0
0
private void table3_Click(object sender, RoutedEventArgs e)
        {
            var tab = new Table();
            var gridLenghtConvertor = new GridLengthConverter();

            tab.RowGroups.Add(new TableRowGroup());
            // 5 is the number of rows
            for (int i = 0; i < 5; i++)
            {
                tab.RowGroups[0].Rows.Add(new TableRow());
                var tabRow = tab.RowGroups[0].Rows[i];
               //sizes the row size 16 characters
                tab.Columns.Add(new TableColumn() { Name = "Column1", Width = new GridLength(160) });
                tab.RowGroups[0].Rows.Add(CreateNewRow("Row" + (i + 1).ToString()));
            }

            richTextBox1.CaretPosition = richTextBox1.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward);
            richTextBox1.Document.Blocks.Add(tab);
            richTextBox1.AppendText(" ");
           // richTextBox1.CaretPosition.InsertTextInRun("");
        }

        private TableRow CreateNewRow(string items)
        {
            TableRow newRow = new TableRow();
            // 2 is the number of columns
            for (int i = 0; i < 5; i++)
            {
                try{

                TableCell cell = new TableCell { BorderBrush = Brushes.Black, BorderThickness = new Thickness(1, 1, 1, 1) };
                Paragraph paragraph = new Paragraph();
                Span span = new Span();
                var newString = items[i];
                cell.Background = Brushes.White;
                span.Foreground = Brushes.Black;
                // span.text = newString;
                paragraph.Inlines.Add(span);
                cell.Blocks.Add(paragraph);
                newRow.Cells.Add(cell);
                }
                 catch (Exception ex)
                {
                //   MessageBox.Show(ex.Message.ToString(), "Error");
                }
            }

            return newRow;
        }

Thank You for your help

Mike


Viewing all articles
Browse latest Browse all 18858


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>