Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
190
Setting forecolor to apply only to certain characters in a row
posted

Is it possible to have characters of different colours in the same cell of an UltraWinGrid that is bound to a datatable? I need to be able to add a red asterisk after certain items in the grid, but can only change the entire cell's text colour with Appearance.Forecolor

Thanks

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    A normal string cell can't do that. But there are a couple of ways you could achieve it.

    One way would be to set the Style of the column to FormattedText (or FormattedTextEditor). This tells the cell to display the cell's content as formatted text, the same way the UltraFormattedLinkLabel or UltraFormattedTextEditor control work. So this would mean that the cell's Value has to include the xml formatting. So that means changing the value in the data source. If that's an option, that's the easiest way to go.

    If you can't change the value of the data, then another option would be to hide the "real" grid column and add an unbound column in it's place. The unbound column's Style would be set to FormattedText (or FormattedTextEditor), just like in the first approach. Then you would use the InitializeRow even to get the value from the "real" cell, modify it to xml to change the colors, and then apply that value to the unbound column.

    A third option would be to use a DrawFilter to simply draw the text of the cell yourself using GDI Plus. The down side of this approach is that it will only work when the cell is not in edit mode. In other words, if the user needs to be able to edit the cell, clicking in the cell would remove the formatting.

Reply Children
No Data