Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Goal:
When you have alot of row inside of a richbox (richbox's height is very short) and you apply a lot of new rows. you want to make the richbox's vertical scrollbar always to be the bottom every time a new row is applied.

Problem:
The question is how to do it?


C#
private void btn_test_Click(object sender, RoutedEventArgs e)
  {
   Table table = newRtb.FindName("MyTable") as Table;
   foreach (TableRow row in table.RowGroups[0].Rows)
   {
    if (row.Background == Brushes.SpringGreen)
    {
     //get value of third cell:
     BlockUIContainer container = row.Cells[2].Blocks.ElementAt(0) as BlockUIContainer;
     TextBlock textBlock = container.Child as TextBlock;
     MessageBox.Show(textBlock.Text);
    }
   }
  }

private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  {
   var tab = new Table();
   tab.Name = "MyTable";
   newRtb.RegisterName("MyTable", tab);


   var gridLenghtConvertor = new GridLengthConverter();

   tab.Columns.Add(new TableColumn() { Name = "Column1", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") });
   tab.Columns.Add(new TableColumn() { Name = "Column2", Width = (GridLength)gridLenghtConvertor.ConvertFromString("*") });
   tab.Columns.Add(new TableColumn() { Name = "Column3", Width = new GridLength(0) });

   tab.RowGroups.Add(new TableRowGroup());

   for (int i = 0; i < 10; i++)
   {
    TableRow tr = new TableRow();
    tr.MouseLeftButtonDown += tr_MouseLeftButtonDown;
    tab.RowGroups[0].Rows.Add(tr);
    var tabRow = tab.RowGroups[0].Rows[i];

    tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Row" + (i + 1).ToString() + " Column1"))) { TextAlignment = TextAlignment.Center });
    tabRow.Cells.Add(new TableCell(new Paragraph(new Run("Row" + (i + 1).ToString() + " Column2"))));

    BlockUIContainer container = new BlockUIContainer();
    container.Child = new TextBlock(){ Text = "Test"};
    tabRow.Cells.Add(new TableCell(container));
   }


   newRtb.Document.Blocks.Add(tab);

  }
Posted
Updated 27-May-14 0:24am
v2
Comments
Naz_Firdouse 27-May-14 6:26am    
Good... Updated the question ...

1 solution

you need to have a vertical scrollbar not a horizontal one.
Use rtb.ScrollToEnd() method which scrolls to the bottom of the richtextbox. if nothing happens, set ScrollViewer.VerticalScrollBarVisibility="Auto" and it soves the issue.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900