We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Multi-Color in Cell

I would like to know how to change the color of the font in the cell. I have used to the cell type as richtextbox but still unable to chnage the color. I can able to change the size and font name of the text but not the color. Waiting for your reply. Thanks Satish

8 Replies

AD Administrator Syncfusion Team March 4, 2004 06:06 AM UTC

To programmatically change the color of richtext in a cell, you could use code like:
private RichTextBox rtb = new RichTextBox();
		
private void button1_Click(object sender, System.EventArgs e)
{// cell 3,1 is richtext, code colors chars 3-6.
	rtb.Rtf = this.gridControl1[3,1].Text;
	rtb.SelectionStart = 2;
	rtb.SelectionLength = 4;
        rtb.SelectionColor = Color.Pink;
	this.gridControl1[3,1].Text = rtb.Rtf;
}
If you want to add the ability to change text color to the drop down panel that you get when you click the button in the richtext cell, then one way to do this is to derive GridRichTextEntryPanel, adding the toolbar item to implement color selection some how. You could use the code snippet above to actually affect the color change. Then you would derive GridRichTextBoxCellModel and GridRichTextBoxCellRenderer to make the cell control use your derived entry panel. All of the work would be in GridRichTextBoxCellRenderer where you would swap the code that uses the private panel member of that class so that in the derived class, the panel would be an instance of your derived panel.


SA Satish March 5, 2004 04:29 AM UTC

Thanks for your help. Superb support. Can this be included in the next release (2.0) please. Thanks Satish >To programmatically change the color of richtext in a cell, you could use code like: >
>private RichTextBox rtb = new RichTextBox();
>		
>private void button1_Click(object sender, System.EventArgs e)
>{// cell 3,1 is richtext, code colors chars 3-6.
>	rtb.Rtf = this.gridControl1[3,1].Text;
>	rtb.SelectionStart = 2;
>	rtb.SelectionLength = 4;
>        rtb.SelectionColor = Color.Pink;
>	this.gridControl1[3,1].Text = rtb.Rtf;
>}
>
> >If you want to add the ability to change text color to the drop down panel that you get when you click the button in the richtext cell, then one way to do this is to derive GridRichTextEntryPanel, adding the toolbar item to implement color selection some how. You could use the code snippet above to actually affect the color change. > >Then you would derive GridRichTextBoxCellModel and GridRichTextBoxCellRenderer to make the cell control use your derived entry panel. All of the work would be in GridRichTextBoxCellRenderer where you would swap the code that uses the private panel member of that class so that in the derived class, the panel would be an instance of your derived panel.


AD Administrator Syncfusion Team March 5, 2004 07:38 AM UTC

We do plan to add better support for RichText, but this cannot be done in the 2.0 release. It will be added in a later release.


LS Lori S. Pearsall March 19, 2004 02:31 AM UTC

Could you expand on the info below? I''ve derived GridRichTextEntryPanel - how do I tell GridRichTextBoxCellRenderer to render my object rather than the standard one? > >Then you would derive GridRichTextBoxCellModel and GridRichTextBoxCellRenderer to make the cell control use your derived entry panel. All of the work would be in GridRichTextBoxCellRenderer where you would swap the code that uses the private panel member of that class so that in the derived class, the panel would be an instance of your derived panel.


AD Administrator Syncfusion Team March 19, 2004 07:20 AM UTC

Below is a sample that shows how to get the renderer to use any UserControl as a dropdown (including one derived from GridRichTextEntryPanel). The idea is to override any method that the renderer baseclass uses to accesse the panel, and make sure you use your user control instead of letting the baseclass use its default GridRichTextEntryPanel. The problem I ran into was not getting the renderer to use the derived GridRichTextEntryPanel, but getting the derived GridRichTextEntryPanel working smoothly with its baseclass. It turned out easier for me to not derive from GridRichTextEntryPanel, but instead just derive from UserControl and add the functionality I wanted without trying to derive GridRichTextEntryPanel. It simply copies the code from GridRichTextEntryPanel to a new derived user control, and adds a button to the font tool bar that allows you to set the color on the selected text. When I tried to to this by deriving GridRichTextEntryPanel, the font toolbar was private and I could not access it to add the button. (This is what I meant when I said it was easier just to derived from UserControl and add things. GridRichTextEntryPanel was not designed for derivation in this respect.) forum11377_44.zip


LS Lori S. Pearsall March 19, 2004 03:05 PM UTC

Many thanks!


LS Lori S. Pearsall June 8, 2004 08:07 PM UTC

This may or may not pertain to the grid ... I''ve used your example and extended it for text & highlight color. It works great in my small test form using a GDBG. Now I''m in my regular project and I added this class in - no changes. The form appears in my grid but all the button images are missing. They display when I open up the class in design mode, but not when I''m running. Here''s the specifics of the parent form : It''s an MDI form using XPMenus & a ControlBar that hosts a child form containing a TabControlAdv that contains a GDBG using this richtext control. I''m thinking that I''m just missing something about the combination of these controls - any suggestions on where to start? Version 2.0.5.1


AD Administrator Syncfusion Team June 8, 2004 08:47 PM UTC

Maybe the imagelist is not being loaded at runtime. If you check it at runtime, does it have the proper images in it?

Loader.
Live Chat Icon For mobile
Up arrow icon