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
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.
Alex
the Telerik team
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?
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.
Please help me on this.
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.
Petya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.