Is it possible to properly display HTML that was exported from a RadRichTextBox in a GridView cell?
The user is allowed to use many of RadRichTextBox's formatting features when entering data into a RadRichTextBox. This data is saved to the database using the HtmlFormatProvider. I am currently saving the HTML as an HTML fragment with inline formatting. The HTML is later pulled from the database and used to populate the RadRichTextBox. I am able to retain the HTML formatting with no problem.
However, the HTML is not formatted properly when displayed in a GridView. It is simply displayed as text, including all HTML tags. Setting DisableHTMLRendering to false for the appropriate columns does not work.
I noticed that simple HTML displays correctly. For example, the following mark-up displays "text" in blue letters as expected:
The following is a simple example of HTML exported from the RadRichTextBox using the HtmlFormatProvider:
<p style="margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;"><span style="font-family: 'Times New Roman';font-style: normal;font-size: 16px;color: #0000FF;">Text</span></p>
21 Answers, 1 is accepted
By default, you can display text, formatted using a subset of HTML in a RadGridView GridViewTextBoxColumn cell.
To do this, you should change the DisableHTMLRendering property for the column to false
You can then display formatted text that follows the HTML-Like formatting article at this link
If you wanted to go further than that, then it would mean creating a custom cell, containing for example a RichTextBox.
You can learn more about creating custom cells here
Hope that helps
Also, I tried to create a custom cell using a RadRichTextBoxElement but this causes my grid to fail to display. I am sure I am missing something. I cannot seem to find a good example of creating a custom cell containing a RadRichTextBoxElement. Do you have a working example or a link to one?
Thanks in advance.
You could use a WebBrowser to display the HTML in your sample. Here is some sample code that should help get you started.
Hope that helps
The html formatting feature available when setting the DisableHTMLRendering property to false supports only a limited number of html tags. Full list of them is available in our online documentation. This feature does not support css styles.
Currently, it is not possible to use our RadRichTextBox as cell content presenter and the only option is the one provided by Richard.
If you have any further questions, we will be glad to help.
the Telerik team
Also how do I get the grid the expand the row height automatically to display the contents?
FYI: I'm using Winforms.RadGridView 2013 Q2 version
Thank you for writing.
Are you sure you are wrapping your cell content with a <html> tag, because that is what is needed to use the HTML formatting. The following code seems to work fine on my end:
To make the rows size themselves automatically according to their content, you need to set the AutoSizeRows property of the grid to true:
And enable text wrapping on the columns:
Additionally the AutoSizeRows mode will make the rows collapse if they have no content, that is why you need to set their MinHeight property if needed:
I hope this helps.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
I followed your instructions to format the text as HTML, but now some of the rendered text appears to be cropped:
I tried changing the font but I still got the same results... do you have any idea what might be causing this?
PS: I'm using telerik version 2012 Q1
Thank you for replying.
Themos, I was not able to reproduce this behavior on my end with the version you specified, or with the latest version. I would like to kindly ask you to provide me with the code you are using to format the RadGridView cells and the html which you are setting as a text, this will allow me to more precisely test your case.
Looking forward to your reply.
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.
I was able to fix the problem, I had to comment out this line:
rgvWarnings.Columns["Warning"].WrapText = true;
but also the position of the empty spaces on the stored procedure populating the column seemed to affect it as well...
I am glad that you were able to resolve the matter.
Let me know, should you have further questions.
The solution Richard suggested uses a custom cell element which internally hosts the standard Winforms WebBrowser control. It also iterates the rows and sets them with a fixed height. You can try using a separate web browser control and set its DocumentText property with the Html. Then you can get the height of the scroll rectangle as discussed here: https://social.msdn.microsoft.com/Forums/windows/en-US/1a825a40-f93e-478f-98cc-ccdcb82f4189/how-to-get-webbrowser-document-height?forum=winforms. Later you can use this value to set the height of each row.
I hope this helps.
Is it possible to display html with table tags within a grid cell.
I tried implementing the solution posted by Richard (using WebBrowser). But I'm facing below issues:
- Not able to edit the cell value
- While scrolling down, the cell content is overlapping the header cell.
Please see the attached
We have a feature request for providing means of displaying and editing Rich Text Content in RadGridView. The item is logged on our feedback portal, here: ADD. RadRichTextEditor - allow RadRichTextBoxEditorElement to be added as custom editor in RadGridView, as elements support clipping. You can subscribe to it and be updated when its status changes.
I am also attaching a project in C# with a custom implementation of the RichTextColumn. It can work with the HTML format and uses a hosted RadRichTextEditor control. I hope that this solution would fit your local setup, however, please note that it may not handle all possible cases, e.g. the custom rich-text cells will not be clipped while scrolling the grid.
I hope this will help.
I am using the solution with GridViewRichTextColumn and it works great in a RadGridView.
I am trying to use it in GridViewRowDetailsExtended (provided by Richard Slade in https://www.telerik.com/forums/details-view-under-row-in-gridview). If you look at the attached image, at the right side the cell goes over the scroll bar. Is there a property or something that I am missing?
Also I tried with child GridViewTemplate, but it not expands.
Following the provided information it seems that you have built a complex custom layout in RadGridView using custom row details and .custom column with RichTextEditor. Considering the picture, it seems like the custom cell that hosts the RichTextEditorElement overlaps the grid and hides the vertical scrollbar that is shown at the right. You should consider setting an appropriate size/width for that cell in order to prevent it from overlapping the scrollbar.
However, I am not familiar with the exact setup that you have in RadGridView. If you need further assistance it would be of great help if you can provide a code snippet with the customized grid that you use. Thus, we could be able to investigate precisely the custom case and provide a suitable solution.
Looking forward to your reply.
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.