4

There seems to be not much information available about this subject so hopefully someone can give some suggestions.

I would like to change color and style of different parts of text in a stringgrid cell.

Example: 20-02-2011 - Document Title

Would it also be possible to show an icon in a stringgrid cell?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
Mike
  • 137
  • 2
  • 6
  • 2
    In one cell? If so, I expect you'll need to use a TGrid, then create a custom cell/column, which has two TText components, one with each font style (but note I've found issues with setting a font in a style). See my article for custom grid cells: http://monkeystyler.com/blog/entry/firemonkey-grid-basics-custom-cells-and-columns – Mike Sutton Mar 06 '12 at 12:00

1 Answers1

0

It is indeed possible to show icons or bitmaps in a string grid, the Monkey Styler blog includes an example of how to customise cell display in a FMX grid.

http://monkeystyler.com/blog/entry/firemonkey-grid-basics-custom-cells-and-columns

Thinking about the other part of your question though, you will have to build a style up to display text in different fonts, as yet FMX does not have a richtext equivalent or HTML rendering components (I'm sure the latter will come, the former I am not confident on getting for a while!). You would have to have a text component in the style for each different font size/style etc, you would need to name the text elements (using binding or stylename properties) and handle the setting of the text contents using code in the ongetvalue and onsetvalue events (I guess you could also use a onapplystyle event) to display some text in bold and some not.

The event handler would then use either a binding - which is easier to set but - in my experience - buggy;

mycell.binding['boldtext']:='sometext';

Or find a style element by stylename by using findstyleresource;

tempobj:=mycell.findstyleresource('boldtext');
if tempobj is ttext then
  ttext(tempobj).text='sometext';

Excuse any bad coding style there, but you get the general idea (I hope) if you set autosize to true for the ttext components in the style and align them left you get - mostly - what you are after. The only issue is that the resulting text doesn't look quite seamless because autosizing and aligning left doesn't really give you the same space between the fonts that you would get with a richtext or HTML display. You should be able to fiddle with the padding (giving it a negative number for the left padding should allow you to remove any extra space) but you have to live with that not being entirely perfect compared to proper font hinting and alignment.

Mike Sutton
  • 4,191
  • 4
  • 29
  • 42
  • Paul, my article relates to TGrid, not TStringGrid. I've never used a string grid in FMX so can't comment on whether it will work or not. – Mike Sutton Mar 18 '12 at 14:23
  • I was only using it as an example that you can in fact get the two components to work in a cell; not that it would really work in the stringgrid component (not that I'd use it, I'd use the grid too) – Paul Foster Mar 20 '12 at 19:18