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

Rich Text Box Backcolor

I am having a problem with the rich text box. By default it seems to have a dark pruprle color if it made the current cell and activated. When it is in the current row but not current it has the desired AlphaBlendSelectionColor. The attached bitmap illustrates the issue.

I tried setting the cells style.Enabled = false in PrepareViewStyleInfo and that fixed the coloring issue but created other problems since having the cell disabled cancels downstream events that I need (CurrentCellMoving, CurrentCellActivating, etc.).

Is there some way to disable the the richtext control but still leave the cell as enabled?

ActiveCellIssue1.zip

5 Replies

RA Rajagopal Syncfusion Team July 19, 2007 02:05 AM UTC

Hi Burke,

If you are looking to have the AlphaBlendSelectionColor for the current cell when the current cell is included in selections, then try the code below in the CellDrawn event and color it there instead of disabling the RichText cells.

private void grid_CellDrawn(object sender, Syncfusion.Windows.Forms.Grid.GridDrawCellEventArgs e)
{
GridCurrentCell cc = this.grid.CurrentCell;

if(e.ColIndex == cc.ColIndex && e.RowIndex == cc.RowIndex)
{
SolidBrush br = new SolidBrush(this.grid.AlphaBlendSelectionColor);
e.Graphics.FillRectangle(br, e.Bounds);
br.Dispose();
}
}

If you just want to change the backcolor of the active richtext cell, then use the below code in the PrepareViewStyleInfo event handler.
void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
if (e.RowIndex == cc.RowIndex && e.ColIndex == cc.ColIndex && e.Style.CellType == "RichText")
{
e.Style.BackColor = Color.Red;
}
}

Let me know if this helps.

Have a nice time.
Regards,
Rajagopal


BH Burke Harris July 20, 2007 11:22 PM UTC

There seems to be a problem with the rich texts controls backcolor. When setting the backcolor (after binding), The control always renders darker than the desired color. No oter controls seem to have this issue. Please see code below.

//Set the column after binding.
GridBoundColumnsCollection gbcc = this.qDataBoundGrid1.Binder.InternalColumns;

gbcc[(int)GridColumns.strDIRECTPHONE - 1].StyleInfo.CellType = "RichText";
gbcc[(int)GridColumns.strDIRECTPHONE - 1].StyleInfo.BackColor = qDataBoundGrid1.AlphaBlendSelectionColor;

//Please See Attached screenshot
//Were AlphaBlendSelectionColor = 74, 51, 51, 102

RichTextIssue2.zip


HA haneefm Syncfusion Team July 21, 2007 12:19 AM UTC

Hi Burke,

You can use the DrawCellEvent, and draw this cell yourself. In your code, you would need to check for Richtext type for the cell, and draw the cell if there are RichText type. Here is a try at this.

void gridDataBoundGrid1_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.Style.CellType == "RichText")
{
string s = e.Style.Text;
e.Style.Text = "";
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Rectangle rect = e.Bounds;
rect.Width = this.gridDataBoundGrid1.Width;
RichTextPaint.DrawRichText(e.Graphics, s, false, rect, rect, Color.Pink, rect, false, 100);
e.Cancel = true;
}
}

Best regards,
Haneef


BH Burke Harris July 23, 2007 03:47 PM UTC

The rich text cell is still rendering incorrectly (please see attachment). Any ideas why the cell backcolor would be different than the one specified in DrawCell?

private void QDataBoundGrid_DrawCell(object sender, GridDrawCellEventArgs e)
{
if (e.Style.CellType == "RichText")
{

string s = e.Style.Text;
e.Style.Text = "";
e.Renderer.Draw(e.Graphics, e.Bounds, e.RowIndex, e.ColIndex, e.Style);
Rectangle rect = e.Bounds;

// AlphaBlendSelectionColor = (74,51,51,102)
Syncfusion.Drawing.RichTextPaint.DrawRichText(e.Graphics, s, false, rect, rect, this.AlphaBlendSelectionColor, rect, false, 100);
e.Cancel = true;
return;
}

}

RichTextIssue3.zip


BH Burke Harris July 23, 2007 07:15 PM UTC

Found a fix.

Here is what I needed to fix the issue.

this.CellRenderers["RichText"].SupportsEditing = false;

Loader.
Live Chat Icon For mobile
Up arrow icon