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

RichTextBox in RadGridView?

5 Answers 416 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Todd
Top achievements
Rank 1
Todd asked on 25 Aug 2010, 07:21 PM

Is it possible to use the RadRichTextBox as a cell within my RadGridView?  Specifically, I have a RadGridView with several columns, and I want the last column to be the RadRichTextBox.  Currently, my Silverlight application has a simple textbox as the last column in the grid.  My customer has asked that I add rich text formatting to the last cell in each row, so I figured I would use the RadRichTextBox.

Here is the code I have for my current textbox in the last column of the RadGridView:

<telerik:GridViewDataColumn Header="Notes" DataMemberBinding="{Binding notes, Mode=TwoWay, Converter={StaticResource DescriptionConverter}}">
    <telerik:GridViewDataColumn.CellEditTemplate>
            <DataTemplate>
            <TextBox AcceptsReturn="True" TextWrapping="Wrap" Text="{Binding notes, Mode=TwoWay}" 
                Height="50" Width="200" VerticalContentAlignment="Top" 
                        HorizontalContentAlignment="Left" VerticalScrollBarVisibility="Auto"/>
                </DataTemplate>
        </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>


If you know how to do this, please step me through the process, post a link to an example of the RadRichTextBox being used in a RadGridView, or post the code for how this is done.

Thanks.
 

5 Answers, 1 is accepted

Sort by
0
Alex
Telerik team
answered on 27 Aug 2010, 07:47 AM
Hello Todd,

It is possible to display RadRichTextBox in a RadGridView cell template. Here are some tips on how to do that:
  • You will have to save the rich content in some of the supported by the RadRichTextBox formats. We recommend Xaml as it is closest to the Silverlight and the RadRichTextBox model.
  • You will have to use DataProvider to bind the content to the RadRichTextBox (more on DataProviders can be found here). Here is how the edit data template will look like if you are using Xaml format:

<telerik:GridViewDataColumn.CellEditTemplate>
  <DataTemplate>
    <Border BorderBrush="#FFC92B" BorderThickness="2">
      <telerik:RadRichTextBox x:Name="richTextBox" Height="60">
        <telerik:RadRichTextBox.Resources>
          <telerikXaml:XamlDataProvider x:Key="XamlDataProvider"  RichTextBox="{Binding ElementName=richTextBox}" Xaml="{Binding Content, Mode=TwoWay}"  />
        </telerik:RadRichTextBox.Resources>
      </telerik:RadRichTextBox>
    </Border>
  </DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>

I've modified the example project  posted on this thread to use RadGridView. You can find it in the attached files.

I hope this was helpful. Any additional feedback is appreciated.

Best wishes,
Alex
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
papadi
Top achievements
Rank 1
answered on 24 Aug 2012, 02:30 PM
I working on WPF and I want to do the same. I tried to use your code, however I get the following exception when I run the application:

Cannot find type 'Telerik.Windows.Controls.RadRichTextBox'. The assembly used when compiling might be different than that used when loading and the type is missing.


If I add the richtextbox directly on my Window it works. I get this error if the richtextbox is in the <telerik:GridViewDataColumn.CellTemplate> node of a GridView.

Any ideas?
0
Petya
Telerik team
answered on 29 Aug 2012, 04:20 PM
Hi Dimitrios,

We were not able to reproduce the exception you have described.

There is a difference in the way that the data providers should be declared than what Alex's snippet illustrates, as in WPF the providers have to be in the visual tree (which is also recommended for Silverlight).

Here a snippet showing how to bind RadRichTextBox using TxtDataProvider and display it in a GridViewDataColumn:

<telerik:GridViewDataColumn Header="Comment" Width="900" >
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <Grid>
                <telerik:RadRichTextBox x:Name="radRichTextBox"  />
                <telerik:TxtDataProvider RichTextBox="{Binding ElementName=radRichTextBox}"  Text="{Binding Path=Comment, Mode=TwoWay}"/>
            </Grid>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>

However, the exception you have reported sounds like a problem with the assembly references. You can find more information about data providers in this article while the required assembly references are listed here. Also, make sure to have referenced the correct version of the assemblies (WPF 3.5 or WPF 4.0) depending on the target framework of your project. 

Please, check if this helps and if you are not able to resolve the issue, open a support ticket and attach a sample project. Regards,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Manish
Top achievements
Rank 1
answered on 24 Oct 2012, 08:46 AM
i am getting a collection of data from database in which for one column i need radrich textbox.I am not able to bind the data which i am getting from my database. Everytime it is coming as empty.

Please help me on this.
0
Petya
Telerik team
answered on 26 Oct 2012, 08:07 AM
Hello Manish,

In order to display data from a database in RadRichTextBox in a GridViewDataColumn, you'd have to do the following:
  • Add all required references. You can find information about those needed for RadRichTextBox here, and about those for GridView here.
  • If the data in your database is not in plain text format, add a reference to the respective data provider. You can read about all supported formats and data providers in this article.
  • Bind the data provider to the rich text box as shown in the snippet in my previous post.
  • Set the ItemsSource property of RadGridView to your collection of data.
this.radGridView.ItemsSource = 

I hope this helps.
 
All the best,
Petya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Todd
Top achievements
Rank 1
Answers by
Alex
Telerik team
papadi
Top achievements
Rank 1
Petya
Telerik team
Manish
Top achievements
Rank 1
Share this question
or