Link to home
Start Free TrialLog in
Avatar of Keith Rotton
Keith RottonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Tables in RichTextBox

I am using Windows Forms and a RichTextBox in c# (Studio 2017) to create a basic editor and now want to add a table. I can do this though the method is very cumbersom, however cannot find an rtf specification, all links I follow are broken. So, two questions:

1. Can anyone point me to an rtf specification?
2. Is there a better way (ie xml?) to do this sort of thing now.
Avatar of Bill Prew
Bill Prew

Here's some reference information on the RTF format:

Rich Text Format (RTF) Specification, version 1.6

And some info specifically targetted toward creating tables in RTF:

1. RTF Tutorial - RTF Pocket Guide [Book]

I'm not aware of an easy way to do this, perhaps creating the table in Excel and then copying in the cells and pasting into RTF, but no idea if automation would "translate" during the copy and generate the RTF for you or not.

There may be some third party controls out there for RTF widgets that simplify tables, but I'm not familiar with any.

Any reason why this has to be done in a RTF control, rather than in it's own grid control, etc?


»bp
Avatar of Keith Rotton

ASKER

I'm trying t create a basic report generator substituting live data values into an editable background. I can't use standard methods for this due to difficualty of getting at the source data (Proprietary Interface). I have got the basic mechanism working, but adding tables would be nice.

Thanks for the link to the specifiction.
instead of RTF/RichTextbox, have you tried to HTMLize your output?
I'd not thought of HTML but was hoping XML. I found this post but with no explanation around it!

richtextbox.Text = @"<table ID=tbtest Runat=server style=width:100%;>
            <tr>
                <td id=tdh" + i + "runat=server>" + myReader[i].ToString() + @"</td>
                <td id=tdh2 runat=server>Pkg Type</td>
                <td id=tdh3 runat=server>Description</td>
                <td id=tdh4 runat=server>Demension</td>
                <td id=tdh5 runat=server>Weight</td>
            </tr>
            <tr>
                <td id=td1 runat=server>test</td>
                <td id=td2 runat=server>test</td>
                <td id=td3 runat=server>test</td>
                <td id=td4 runat=server>test</td>
                <td id=td5 runat=server>test</td>
            </tr>
            <tr>
                <td id=td6 runat=server>test</td>
                <td id=td7 runat=server>test</td>
                <td id=td8 runat=server>test</td>
                <td id=td9 runat=server>test</td>
                <td id=tdh10 runat=server>test</td>
            </tr>
        </table>";

Open in new window

This is HTML. It is creating a table of 3 rows * 5 columns..
I get that, but I cant find any documentation that explains how to use rich text box with html, only rtf!
I think it is true that you can use HTML markup inside the RTF control, but I'm not sure I have seen that documented.  Seems to me I've done that for simpler things like bolding, or changing color.  I didn't suggest it originally because I wasn't sure if tables would be supported.


»bp
I would use a WebBrowser control to render a HTML report. https://www.emoreau.com/Entries/Articles/2007/04/The-WebBrowser-control.aspx
Thanks Éric, I shall look in to that possibility.
Eric's keeps posting exactly what I'm thinking as I read through this.

If I were in your spot, I'd definitely do this in HTML markup. It's lightweight, easy to write and read, highly compatible (readable by nearly any operating system in active use today), and is a great starting point for conversions (e.g. if someone wants to convert to PDF afterwards, there are several PDF virtual print drivers).

And if the user needed to be able to tweak the final content via an editing interface, it can be as easy as wrapping everything inside a content-editable DIV tag:
<p>I am just read-only HTML.</p>
<div contenteditable="true">
<p>I can be edited like a Word document by anyone looking at this!</p>
</div>

Open in new window

Lokks like HTML it is then. Thanks for th input guys.
@Keith Rotton,

Are you all set with this now, or do you need more help?  If all set, could you please close it out now.  If you need help with the question close process take a look at:



»bp
ASKER CERTIFIED SOLUTION
Avatar of Keith Rotton
Keith Rotton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why did you select your own comment as the answer? Your previous comment had indicated you were going with HTML, so please find which comments led you to that final choice/result and mark them as the solution.

If you didn't go with HTML, then please describe your final result.
I ended up sticking with RTF due to the amount of work already invested. When needing to include tables I use Wordpad to create the table then paste it into the editor section of my application.
Okay - marking that as the solution, then. Thanks!