Hi,I want to color a part of the text in a cell. I achieve this using ColumnStyle.FormattedText and html to set the color. However, this doesn't work when the cell is disabled. The text color always stays gray.I've tried to use CellActivation.NoEdit and set the part of the text that should not be colored to SystemColors.GrayText, but then the cell activates on click. Setting the CellClickAction to something else doesn't resolve this.Can anyone point me in the right direction how to set part of a text color in a disabled cell?Thanks in advance.Vabi (TorX)
This behavior is by design, the logic being if we didn't gray out the text, the user might be mislead into thinking they can navigate to a URL or something (a popular use case for the FormattedText style is to show hyperlinks).
In my opinion, the easiest way to solve this problem is to set the cell's Activation to ActivateOnly, so that it doesn't go into edit mode, and handle/cancel the BeforeCellActivate event, so that clicking on a cell in that column does not activate it.
The attached sample demonstrates how to do this.
I understand it's by design, but I was hoping there was something to work around that like the ForeColorDisabled property on the Appearance object (which I can't use unfortunately because only a part of the text should be colored).
Your solution however looks nice. However when I click on a cell, the row still gets activated. I've tried to set CellClickAction to CellSelect, but that didn't work. Then I downloaded your solution to see if you worked around that, but I can't open the zip (it looks like it's corrupted).
Thanks for your help!
I assume you're satisfied so I closed the case. You can reopen it at any time if you need to.
That's a nice workaround. Thank you for your help Brian!
The attached sample demonstrates how to use BeforeRowDeactivate and BeforeCellDeactivate to cache the last activated cell/row so that it can be restored in the event the user tries to activate the formatted text cell.
I'm afraid there are some limitations that might make this solution unusable for you, since it is implied that the solution should mimic disabled behavior. For example, when a cell is actually disabled, navigation will pass over it and onto the next cell that can be activated, which this sample does not do. There may well be other aspects of the disabled behavior that is not possible to emulate with this approach, in which case you will have to modify it to suit your needs, or submit a product idea for the ability to override the default disabled appearance.
The row activation problem was implied because I want to mimic the disabled behaviour.
Thank you for the suggestion. I had looked at the BeforeRowActivate myself, but I noticed it's not cancellable. Even if it was, the event gets called before BeforeCellActivate, so I would be too late caching the right cell.
In the attached sample, I did not work around the row activation issue, because I wasn't aware that was a problem for you.
To prevent this, you could cancel BeforeRowActivate as well, but you would have to do something like cache the last cell that was attempted to be activated, and cancel BeforeRowActivate only when that cell is in the formatted text column.
I re-attached the sample...no idea why but when I tried to open it from the attachment, it was empty.