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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Setting TextColor property in renderer

Thread ID:

Created:

Updated:

Platform:

Replies:

63559 Jul 5,2007 11:35 AM UTC Jul 10,2007 09:54 PM UTC WinForms 3
loading
Tags: GridControl
Stephen Main
Asked On July 5, 2007 11:35 AM UTC

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?


haneefm [Syncfusion]
Replied On 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

Stephen Main
Replied On 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

haneefm [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;