Forum > LCL

Form AutoSize and TSringGrid

(1/2) > >>

mas steindorff:
I have a TStingGrid on it's own form that I add a line to each time it is shown.  I would like the form to re-size itself to show all of the string grid.  I've tried setting the forms AutoSize to true but that doesn't seem to do anything. 

zariq:
the only way the form will resize is if the side of the  stringgrid drops off the edge of the form. If you add a column or row to the stringrrid, then what happens depends on the scrollbars property. Set it to ssautoboth. If you dont want scrollbars on the stringgrid then you have to set the height and width of the stringgrid to show all rows and columns. In the latter case you will end up with scroll bars on the form.

mas steindorff:

--- Quote from: zariq on October 11, 2010, 06:46:00 pm ---the only way the form will resize is if the side of the  stringgrid drops off the edge of the form. If you add a column or row to the stringrrid, then what happens depends on the scrollbars property. Set it to ssautoboth. If you dont want scrollbars on the stringgrid then you have to set the height and width of the stringgrid to show all rows and columns. In the latter case you will end up with scroll bars on the form.

--- End quote ---
I've tried both settings for the scrollbars (none and autoboth).  in both cases the form size stays fixed at it's original size (or last set size if I drag it at run time).  I've also tried calling the form's adjustsize and doautosize without success.

zariq:
Hi.

Sorry if my reply was unclear.

I you want the form and stringgridgrid size to stay fixed but want to add scrollbars to the stringgrid so you can scroll up and down to view all the items then you need to set the stringgrids scrollbars property to the the following

ssvertical : fixed vertical scrollbar
sshorizontal : fixed horizontal scrollbar
ssboth        : fixed both horizontal and vertical scrollbars

These settings will put a scroll bar on the stringgrid whether it needs it or not. I you want it to add and remove the scrollbars automatically when the need arises then then set it to ssautoboth,
ssvertical or sshorizontal.

If you dont want any scroll bars on the stringgrid but want to resize the form then set the stringgrid scrollbars property to ssnone and in the preparecanvas event of the stringgrid  set the result of the stringgrid rowcount property multiplied by the stringgrid rowheights property to the stringgrids height property.

eg.
 stringgrid1.height := stringgrid1.rowcount*stringgrid1.rowheights[any valid row];.

That sould work if all your rows are the same height, if not then you have to take that into consideration.

and obviously you will have to set the forms autosize to true.

Bye.

mas steindorff:
well, I tried your suggestions without any success :'(.  they were basically the same as I had.  I was trying to use the form auto size to avoid having to play with the math of adding the heights of all of the objects. Autosize and stringgrids just doesn't work.  perhaps it something to do with the status bar.

I've resorted to the old grunt way  :'(
(was just trying to learn something new but is may just be too new)
I read there will be a new release soon, I'll retry after It comes out.

Navigation

[0] Message Index

[#] Next page

Go to full version