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

RichTextBox in GridView with DataPager is not updated when page is changed

4 Answers 127 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 03 Oct 2011, 10:58 AM
Hello

Im not sure where to place this, so here we go.

I have a RadGridView which ItemsSource is set to the PagedSource of a RadDataPager which Source is set to an ObservableCollection in my viewmodel. One of the columns in the gridview contains a readonly RadRichTextBox and a HtmlDataProvider as a rich textbox resource which is bound to a string property containing Html. All this is working as intended, and when I update my observable collection the gridview displays the correct items and the richtextboxes correctly displays the formated text for each row.

My problem is, that when change the page using the datapager, all the columns are updated with the next set of items EXCEPT the richtextboxes column, which all stays the same.

Below is the xaml for the gridview, circhtextbox column and datapager. My codebehind contains nothing but the InitializeComponents() method-call.

<telerik:RadGridView Name="SearchResultGridView" ShowGroupPanel="False" IsFilteringAllowed="False" IsReadOnly="True" CanUserSortColumns="False" CanUserResizeColumns="False" CanUserReorderColumns="False" AutoGenerateColumns="False" CanUserSelect="False" ItemsSource="{Binding Path=PagedSource, ElementName=SearchResultDataPager}" Margin="20,10,20,0">
  <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Id" DataMemberBinding="{Binding LabelId}" />
        <telerik:GridViewDataColumn Header="Name" TextWrapping="Wrap" DataMemberBinding="{Binding Label.LabelName}" />
        <telerik:GridViewDataColumn Header="Comment" TextWrapping="Wrap" DataMemberBinding="{Binding Label.Comment}" />                   
        <telerik:GridViewDataColumn Header="Text" Width="*" DataMemberBinding="{Binding LabelText, Mode=TwoWay}">
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <telerik:RadRichTextBox x:Name="LabelTextRichTextBox" IsHitTestVisible="False" IsReadOnly="True" Margin="3">
                        <telerik:RadRichTextBox.Resources>
                            <telerikHtml:HtmlDataProvider x:Key="HtmlDataProvider" RichTextBox="{Binding ElementName=LabelTextRichTextBox}" Html="{Binding LabelText, Mode=TwoWay}" />
                        </telerik:RadRichTextBox.Resources>
                    </telerik:RadRichTextBox>
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn Header="Locale" DataMemberBinding="{Binding Locale.LocaleName}" />
        <telerik:GridViewColumn>
            <telerik:GridViewColumn.CellTemplate>
                <DataTemplate>
                    <Button Content="Edit" Command="{Binding Source={StaticResource DataContextProxy}, Path=DataSource.EditLabelCommand}" CommandParameter="{Binding}" Margin="2" Width="35" />
                </DataTemplate>
            </telerik:GridViewColumn.CellTemplate>
        </telerik:GridViewColumn>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>
<telerikData:RadDataPager x:Name="SearchResultDataPager" Source="{Binding Path=SearchResult}" PageSize="1" IsTotalItemCountFixed="True" Margin="20,2,20,10" />

What is the problem? Why is the content of the RadRichTextBox'es not updated when the page is changed?

4 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 03 Oct 2011, 11:58 AM
Hello Martin Høj,

Please find the answer to your question in this forum thread.

Regards,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Martin
Top achievements
Rank 1
answered on 03 Oct 2011, 12:18 PM
Hello

That did not fix my problem. I corrected my xaml as follows:

<telerik:GridViewDataColumn Header="Text" Width="*" DataMemberBinding="{Binding LabelText, Mode=TwoWay}">
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate>
            <StackPanel>
                <telerikHtml:HtmlDataProvider RichTextBox="{Binding ElementName=LabelTextRichTextBox}" Html="{Binding LabelText, Mode=TwoWay}" />
                <telerik:RadRichTextBox x:Name="LabelTextRichTextBox" IsReadOnly="True" Margin="3" />                                                                       
            </StackPanel>                               
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewDataColumn>

But now when i try to change the page i get an exception. See the attached screendump.
0
Accepted
Iva Toteva
Telerik team
answered on 06 Oct 2011, 01:39 PM
Hello Martin,

Thank you for the follow-up. There seems to be a problem in this scenario. We will look into the issue and try to fix it.
As a workaround, you can implement a RichTextControl that inherits from RadRichTextBox and exposes a RichText property. This control must update the RichText property whenever the document of the RadRichTextBox changes and vice versa - update the document when the string property changes. Please find attached a demo that illustrates how this approach can be implemented.

Kind regards,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Martin
Top achievements
Rank 1
answered on 06 Oct 2011, 02:39 PM
Thank you for the reply. That workaround works well.
Tags
RichTextBox
Asked by
Martin
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Martin
Top achievements
Rank 1
Share this question
or