views:

342

answers:

2

I want my users to be able to enter text in a Rich Text box and the RTF output be saved to the database.

Currently I have the RichTextBox bound to the field in the database, but it strips formatting when it's saved. How can I prevent this?

Also, how can I attach a formatting toolbox, (like what's in Wordpad) so my users can change the formatting?

And, last, I can't right click in the box or use Ctrl+C, Ctrl+V or anything like that, why is that? How can I fix it?

+2  A: 

Ok, there are alot of questions there, I'll try to answer what I can.

1) Databinding is great for displaying data, but I personally NEVER use DataBinding for saving stuff back to the database. I've always found it to be "too much magic happening" and that I needed more control. Therefore, I would strongly suggest that you handle the insertion yourself (via LINQ to Sql or ADO.Net whatever). The RichTextBox control has an RTF property which you can get to do the insert manually into the database.

2) As for getting formatting buttons on top, it's not as simple as changing a property and be done with it. You'll have to implement that custom control yourself. Have a look at this CodeProject article. IT's in VB.NET, but maybe it'll give you some ideas: http://www.vbdotnetheaven.com/UploadFile/scottlysle/WordProcessor09122006234320PM/WordProcessor.aspx

3) Not quite sure...

BFree
A: 

For number 3, isn't there a property on the RichTextBox that enables the Context menu? I might've seen this on a different control but maybe it also has that property.

Jordy Boom
ContextMenuStrip, but it's set to (none)
Malfist