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

Setting TextColor property in renderer

Hi,

I have inherited the GridDropDownMonthCalendarCellRenderer and have been using it to successfully read the values of cells to which the calling model is assigned.

What I cannot seem to do is change the TextColor of the cell. I know the renderer is wired in properly to CellModel etc...

I have boiled the problem down to it's essence as shown below: (if this is placed in a custom renderer then the cell color remains black).


protected override bool OnSaveChanges()
{
this.CurrentStyle.TextColor = Color.Red;

return base.OnSaveChanges();
}


How can I persist text color changes using a cell renderer?

Any ideas?


3 Replies

HA haneefm Syncfusion Team July 5, 2007 05:37 PM UTC

Hi Steve,

In your custom cell renderer, you can subscribe the QueryCellInfo event and set the TextColor of the cell using this event. Below are the code snippet

this.Grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(HandleQueryCellInfo);

//the handler
private void HandleQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{e.Style.TextColor = Color.Red;}

Best regards,
Haneef


SM Stephen Main July 10, 2007 04:31 PM UTC

I have partialy solved this problem by overriding the OnPrepareViewStyleInfo scince I would like the custom formatting changes to be made from within the model rather than subscribing to events (could get messy). The problem that I have now is that any changes I make to formatting do not persist in subsequent calls to OnPrepareViewStyleInfo. The solution to this seems to be to apply the formatting every time OnPrepareViewStyleInfo is called which seems expensive (I call a validation function of a custom property object on the cell model each time OnPrepareViewStyleInfo is called).

If I try to put in an updateFormatting flag that is set to true each time OnSaveChanges() is called, the changes are not persisted for calls to OnPrepareViewStyleInfo where the flag is false.

Pseudo c# shown below:
public override void OnPrepareViewStyleInfo(GridPrepareViewStyleInfoEventArgs e)
{
if (updateFormatting)
{
//get the model object
MyCustomClass myCustomClass = (MyCustomClass)((MySyncStyleProperties)e.Style).Model;
if (myCustomClass.MyValidationFunc())
{
e.Style.TextColor = dateOKColor;
}
else
{
e.Style.TextColor = dateForbiddenColor;
}
e.Style.CellTipText = dateOrTenorModel.Tip;
updateFormatting = false;
}
base.OnPrepareViewStyleInfo(e);
}

There must be a better way. Any ideas?

Thanks,
Steve


>Hi Steve,

In your custom cell renderer, you can subscribe the QueryCellInfo event and set the TextColor of the cell using this event. Below are the code snippet

this.Grid.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(HandleQueryCellInfo);

//the handler
private void HandleQueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{e.Style.TextColor = Color.Red;}

Best regards,
Haneef


HA haneefm Syncfusion Team July 10, 2007 09:54 PM UTC

Hi Steve,

The reason is that you are using the OnPrepareViewStyleinfo event. OnPrepareviewStyleInfo method does not store any styleInfo properties in a grid. It just set the visual apperence of the grid. It depends on the data stored in a grid. If you want to set as well as store the style of the cell, then you can handle the QueryCellInfo event of the grid.

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon