This is a migrated thread and some comments may be shown as answers.

Bug with multiple RadRichTextBox in RadTabControl

6 Answers 124 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 07 Jan 2011, 02:53 AM
Hi,

In some situation, when I call the "RichTextBox.Insert", I get the following error: "Object reference not set to an instance of an object"

I did investigate the problem and it will occur for every RichTextBox in a RadTabControl, execpt the first one.

Example #1:

<Grid>
    <telerik:RadTabControl Name="RadTabControl1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
      <telerik:RadTabItem Header="Recherche" Height="23" HorizontalAlignment="Left" Name="RadTabItem1" VerticalAlignment="Top" Width="80">
          <telerik:RadRichTextBox Margin="0" Name="RadRichTextBox1"/>
      </telerik:RadTabItem>
      <telerik:RadTabItem Header="Rapport" Height="23" HorizontalAlignment="Left" Name="RadTabItem2" VerticalAlignment="Top" Width="80">
          <telerik:RadRichTextBox Margin="0" x:Name="RadRichTextBox2"/>
      </telerik:RadTabItem>
      <telerik:RadTabItem Header="Analyse" Height="23" HorizontalAlignment="Left" Name="RadTabItem3" VerticalAlignment="Top" Width="80">
          <telerik:RadRichTextBox Margin="0" x:Name="RadRichTextBox3"/>
      </telerik:RadTabItem>
    </telerik:RadTabControl>
</Grid>

In example #1, RadRichTextBox2 and RadRichTextBox3 will raise an error if they call the Insert function.  Howerver RadRichTextBox1 won't raise any error.


Example #2
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="33*" />
        <ColumnDefinition Width="33*" />
        <ColumnDefinition Width="33*" />
    </Grid.ColumnDefinitions>
    <telerik:RadRichTextBox Grid.Column="0" x:Name="RadRichTextBox1" />
    <telerik:RadRichTextBox Grid.Column="1" x:Name="RadRichTextBox2" />
    <telerik:RadRichTextBox Grid.Column="2" x:Name="RadRichTextBox3" />
</Grid>

In exemple #2, no error will be raised.

Is there a bug or amI doing something wrong here?

Regards,

Simon

6 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 08 Jan 2011, 07:39 PM
Welll I don't know what was the problem but I solved the problem by setting the text like this:

 

 

 

radRichTextBox.Document = New Telerik.Windows.Documents.FormatProviders.Txt.TxtFormatProvider().Import("Some text..."

 

 

0
Iva Toteva
Telerik team
answered on 10 Jan 2011, 03:20 PM
Hello Simon,

The Document of RadRichTextBox needs to be measured and arranged before text can be inserted in it. These actions are automatically performed when the rich text box is shown (measured and arranged by the framework as is the case with RadRichTextBox1), but for the other two, you would need to manually invoke the following method:

private void MeasureAndArrangeDocument(RadRichTextBox radRichTextBox)
{
    RadDocument doc = radRichTextBox.Document;
    doc.Measure(RadDocument.MAX_DOCUMENT_SIZE);
    doc.Arrange(new RectangleF(PointF.Empty, doc.DesiredSize));
}
like this:
MeasureAndArrangeDocument(this.RadRichTextBox1);
MeasureAndArrangeDocument(this.RadRichTextBox2);
MeasureAndArrangeDocument(this.RadRichTextBox3);
   ***
//Now you can insert text
this.RadRichTextBox3.Insert("SDFdsfsdfsdfsdF");
This only needs to be done the first time the application is started, for example in the handler for the Loaded event of the RadTabControl.

The approach you have adopted works in case you want to set the text only once from code-behind. TxtFormatProvider creates a new RadDocument on Import, which is also not measured and arranged and if you try to manipulate it before it is shown, you will get an exception again. 

If you have any other questions, do not hesitate to contact us again.

Greetings,
Iva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Simon
Top achievements
Rank 1
answered on 10 Jan 2011, 04:27 PM
Hello Iva,

Thanks for the solution and the explainations.

I did implement you code and the code doesn't crash anymore. 

However, if I use your solution instead of the TxtFormatProvider, there's 2 small bug with display.

1- If I change the font size of the text, the change are not displayed.
2- When a RadExpander expands and change the size of the RadRichTextBox, some word are overlapping each others.

Both bugs are corrected when the RadRichTextBox is resized manually.

I remember someone who mentionned an overlapping problem with the RadRichTextBox on this forum.  Are these problems related?

Regards,

Simon
0
Accepted
Iva Toteva
Telerik team
answered on 12 Jan 2011, 05:46 PM
Hello Simon,

I am glad to hear that your previous issues were successfully overcome. 
As for the bugs with the display you have encountered, I was not able to reproduce them.

  1. Changing the FontSize of the text:
Are you changing the FontSize programmatically? If so, the following line should be working, i.e. Changing the font size of the selected text:
  1. this.radRichTextBox.ChangeFontSize(Unit.PointToDip(50));
    Note that this method sets the font size in Dips, whereas the SelectionMiniToolBar and RadRibbonComboBox show the value in Points.
    If you want to set the FontSize of the text you are about to insert, you have to invoke the following methods in that order:
    this.radRichTextBox.Document.Selection.Clear(); //if you skip that, any selected text will be deleted
    this.radRichTextBox.ChangeFontFamily(new FontFamily("Arial Black"));
    this.radRichTextBox.ChangeFontSize(Unit.PointToDip(50));
    this.radRichTextBox.Insert("some Arial Black enormous text");
  2. As for the issue with the RadExpander, can you give us some details on your implementation, as it works fine on our side?
Looking forward to your reply.

Best wishes,
Iva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Simon
Top achievements
Rank 1
answered on 27 Jan 2011, 08:58 PM
Thanks you Iva,

I changed my code and now everything is ok.

Regards,

Simon
0
Iva Toteva
Telerik team
answered on 28 Jan 2011, 04:59 PM
Hello Simon,

We are glad that the issue was solved.
If you meet any other problems, do not hesitate to get back to us.

Greetings,
Iva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
RichTextBox
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or