Board index » cppbuilder » resizing a stringgrid

resizing a stringgrid


2004-01-02 04:59:25 AM
cppbuilder62
Hi,
I have a problem using a StringGrid.
When the StringGrid resizes i want the columns to resize too,
so the complete stringGrid is filled up with columns (leaving
no white space).
I have this already working (width of a column = width of stringGrid /
colcount).
But now i want to consider the width of the different columns in the Grid
(not all columns have to be of the same width).
How do i have to do this?
Thanks.
 
 

Re:resizing a stringgrid

"Clouds" < XXXX@XXXXX.COM >wrote in message
Quote
But now i want to consider the width of the different
columns in the Grid (not all columns have to be of the
same width).
It is a little unclear what exactly you are looking to do. Please elaborate
with more details, possibly even an actual example as well. where are your
widths coming from exactly?
Gambit
 

Re:resizing a stringgrid

"Clouds" < XXXX@XXXXX.COM >wrote:
Quote
When the StringGrid resizes i want the columns to resize too,
so the complete stringGrid is filled up with columns (leaving
no white space).
[snip]
But now i want to consider the width of the different columns
in the Grid (not all columns have to be of the same width).
You will have to remember the percentage of a column's with from
the grid's width. Say you have:
widths: Col1: 20px, Col2: 60px, Col3: 120px =>Grid: 100px
factors: 0.1 + 0.3 + 0.6 = 1.0
Store these factors in a vector, array or for instance in the
grid's objects of row 0.
Once the grid's width changes re-calculate the col widths:
Grid 150px =>Col1 0.1*150=15, Col2 0.3*150=45, Col3 0.6*150=90
 

{smallsort}

Re:resizing a stringgrid

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schreef in
bericht news:3ff49aa1$ XXXX@XXXXX.COM ...
Quote

"Clouds" < XXXX@XXXXX.COM >wrote in message
news:3ff48b39$ XXXX@XXXXX.COM ...

>But now i want to consider the width of the different
>columns in the Grid (not all columns have to be of the
>same width).

It is a little unclear what exactly you are looking to do. Please
elaborate
with more details, possibly even an actual example as well. where are
your
widths coming from exactly?


Gambit


Ok, i will try to explain what i mean:
Imagine a form with a StringGrid with 3 columns.
A user can resize the form which also resizes the StringGrid (align
alClient).
When the form is loaded the 3 columns fill the complete StringGrid
(each width of the column = 1/3 * width of StringGrid).
Now the user decides to enlarge the first column
(which reduces the width of the other columns).
Next he resizes the form (and indirectly the StringGrid).
At the moment, after resizing the form, the columns will
fill up the StringGrid, taking each 1/3 of the StringGrid's width
(and the action of the user to make the first column bigger get's lost).
That's not what i want. The first column has to be a factor bigger than
the other two columns in the Grid, after resizing it.
What i already did is storing the factor in an array, but i can't figure out
when i have to update them. I would say on a OnColumnResize event
but that doesn't exist. These factors then can be used on a FormResize event
(what Thorsten Kettner also suggested) to calculate the new width of each
column.
Hope i make myself clear,
Clouds
 

Re:resizing a stringgrid

Try to calculate the enlargement/reduction factor of the grid when
it resizes as
factor = OldStringGridWidth/NewStringWidth;
then multiply each and every Column Width by this factor
so that the new Column Width will become
NewColumnWidth = factor * OldColumnWidth;
Rodolfo
"Clouds" < XXXX@XXXXX.COM >wrote in message
Quote
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schreef in
bericht news:3ff49aa1$ XXXX@XXXXX.COM ...
>
>"Clouds" < XXXX@XXXXX.COM >wrote in message
>news:3ff48b39$ XXXX@XXXXX.COM ...
>
>>But now i want to consider the width of the different
>>columns in the Grid (not all columns have to be of the
>>same width).
>
>It is a little unclear what exactly you are looking to do. Please
elaborate
>with more details, possibly even an actual example as well. where are
your
>widths coming from exactly?
>
>
>Gambit
>
>

Ok, i will try to explain what i mean:

Imagine a form with a StringGrid with 3 columns.
A user can resize the form which also resizes the StringGrid (align
alClient).

When the form is loaded the 3 columns fill the complete StringGrid
(each width of the column = 1/3 * width of StringGrid).

Now the user decides to enlarge the first column
(which reduces the width of the other columns).

Next he resizes the form (and indirectly the StringGrid).
At the moment, after resizing the form, the columns will
fill up the StringGrid, taking each 1/3 of the StringGrid's width
(and the action of the user to make the first column bigger get's lost).

That's not what i want. The first column has to be a factor bigger than
the other two columns in the Grid, after resizing it.

What i already did is storing the factor in an array, but i can't figure
out
when i have to update them. I would say on a OnColumnResize event
but that doesn't exist. These factors then can be used on a FormResize
event
(what Thorsten Kettner also suggested) to calculate the new width of each
column.

Hope i make myself clear,

Clouds


 

Re:resizing a stringgrid

"Clouds" < XXXX@XXXXX.COM >wrote:
Quote
What i already did is storing the factor in an array, but i
can't figure out when i have to update them. I would say on a
OnColumnResize event but that doesn't exist.
Yes, it's a pity that such an event does not exist. What you
can do is to use either OnMouseUp or OnDrawCell.
 

Re:resizing a stringgrid

"Clouds" < XXXX@XXXXX.COM >wrote:
Quote
[...] That's not what i want. The first column has to be a
factor bigger than the other two columns in the Grid, after
resizing it.
Then you can't use the Align property. Instead, set it to
alNone and place a panel under it with Align set to alClient.
Then use the form's OnResize event to set the grid size (and
column sizes) manually.
The panel's new width will tell you what to set the grid width
to. All you have to do is look at the current width and the
new width, get the difference, divide by the number of columns
and you have the number of pixels to adjust the individual
columns. If the old width is greater than the new, subtract
the factor from each column, otherwise add it to the column
size.
~ JD