How To Make Table in Rich Textbox Using C#
August 12, 2012 at 2:15 AM
Is it possible To Generate Table in Rich TextBox?
Answer is yes.RichTextBox control is always the best choice when it is required for the user to edit formatted text, images, tables and any other such rich contents wich is not possible in simple textbox. RTF (Rich Text Format) Specification provides formats for text and graphics that can be used with different output devices, operating environments, and operating systems.
RTF documents created with different software applications under different operating systems can be transferred between those software applications and operating systems .
For understanding the possibilities of Rich textbox better try the small sample below which creates a table in Rich Textbox with 5 rows and 3 columns.
private void SetTableToRichtextbox()
//Since too much string appending go for string builder
StringBuilder tableRtf = new StringBuilder();
//beginning of rich text format,dont customize this begining line
//create 5 rows with 3 cells each
for (int i = 0; i < 5; i++)
//A cell with width 1000.
//Another cell with width 2000.end point is 3000 (which is 1000+2000).
//Another cell with width 1000.end point is 4000 (which is 3000+1000)
tableRtf.Append(@"\intbl \cell \row"); //create row
this.richTextBox1.Rtf = tableRtf.ToString();
The above mentioned table creation has a limitation that you can not enter lengthy text in columns which is a limitation of the .NET rich texbox control.So I have written another article recently to overcome this limitation which allows auto text wrap in table columns.See the article