o815 0 Posted October 8 Hey there, I have following problem: I have a Grid with 14 Columns and dynamically 1...20 Rows. Now I want to be sure that the text in every cell (also header cells) will fit into the grid, but with following rule: The fontsize should be adjusted, meaning if any cell-text won't fit, the font-size would be decreased until it fits. I the other hand, if there is enough space in cell, the fontsize will increase. I tried such functions like Autosize := true AutoFitColumns() But they won't affect the fonzsize, so it seems I have to iterate through every fontsize and see if it fits. Someone had already a similar problem? Share this post Link to post
PeaShooter_OMO 11 Posted October 8 (edited) @o815 TAdvStringGrid does not have any functionality to satisfy your request, at least not as far as I can remember. You will have to iterate font sizes to do that. You can have a look at Canvas.TextHeight Canvas.TextWidth Canvas.TextExtent Edited October 8 by PeaShooter_OMO Share this post Link to post
PeterBelow 238 Posted October 8 7 hours ago, o815 said: Hey there, I have following problem: I have a Grid with 14 Columns and dynamically 1...20 Rows. Now I want to be sure that the text in every cell (also header cells) will fit into the grid, but with following rule: The fontsize should be adjusted, meaning if any cell-text won't fit, the font-size would be decreased until it fits. I the other hand, if there is enough space in cell, the fontsize will increase. I tried such functions like Autosize := true AutoFitColumns() But they won't affect the fonzsize, so it seems I have to iterate through every fontsize and see if it fits. Someone had already a similar problem? You would have to draw cell content yourself (OnDrawCell event) to achieve that, but in my opinion such behaviour is a horrible idea in the first place. It would give a very uneven grid appearance and you will also have the problem that larger font sizes than the grid default will also require a bigger row hight to avoid text cut off at the bottom. Either adjust the column width or (more difficult) implement word wrap for cells with longer text. That also requires drawing the cell yourself and adjusting the row hight, which is tricky since it will trigger a redraw of the row and thus fire OnDrawCell again. An alternative is to use the grid with reasonable default font size and column autofit and place a panel or frame with individual edit and memo fields below it. Clicking on a grid row shows the content of the row in the individual controls of the panel, the content of which the user can scroll if required. 2 Share this post Link to post