Jump to content
Sign in to follow this  
o815

Auto-Fontsize , Colwidths, RowHeights at Grid / TMS TAdvstringgrid

Recommended Posts

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
Posted (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 by PeaShooter_OMO

Share this post


Link to post
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.

  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×