I’m working on a C# application (windows form) which has a DataGridView which is saved in a database (each cell considered as a string). What I want to do is to add a button that will color the text (or the cell BackColor) in such a way that when I print (on a paper) my database content, the color stays.
What I was thinking is to convert the cell string to RTF but I don’t really know how to do this for the cells do not support RTF natively. I’d like to avoid as much as possible changing the DataGridView to a rich DataGridView so I was wondering if i can just do something like add this string when I save a colored cell:
“{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fswiss\fprq2\fcharset0 Microsoft Sans Serif;}{\f1\fnil\fcharset0 Microsoft Sans Serif;}}
{\colortbl ;\red255\green0\blue0;}
\viewkind4\uc1\pard\ltrpar\cf1\f0\fs17 ” + cell.Value.ToString() + “\cf0\f1\par”
The tricky thing is that when I open my application, I want to read each cell’s string, and apply the RTF style to the cell style. For exemple I save a red cell which contains “hello”, when I open my application I want the cell to be red, but when I print (paper again) I want the text to be red (so parse the RTF on open to separate the text from the format).
Any ideas? Thanks in advance. 🙂
Forgot to say I found the correct RTF string, it is the following:
When starting the application I just check if the string cointains the RTF header, then I just split the text to keep the value and apply style to the cell.