[Gambas-user] Gridview Q and determining width of a string

Richard Terry rterry at ...1823...
Fri Jun 1 15:27:58 CEST 2012


Rolf-Werner Eilert wrote:
> Am 01.06.2012 00:27, schrieb Richard Terry:
>   
>> Hi List
>>
>> A few qridview questions if anyone has time.
>>
>> I'm loading a grid with variable length strings, and want to adjust the
>> column widths to match, or have the option to increase the height of a
>> cell with word-wrap within the cell.
>>
>> I wondered if anyone has gone down this path before.
>>
>> I tried having a hidden label with auto-resize = false, setting the
>> label.text property to the string, reading the width, then setting the
>> max width of all the strings to the column width. This works but seems
>> messy, plus I found I had to put a Wait command after each label update
>> or the label didn't resize.
>>
>> Also would be interested in how to wrap text within a grid cell.
>>
>> Regards
>>
>> richard
>>     
>
> Ok, I just did some trial code, and it may run like this:
>
> - Give a fixed Column.Width.
> - Browse the strings and find out if Table.Font.Width(of the 
> investigated Cell) is greater than the appropriate Column.Width.
> - If yes: set the string into a TextLabel which has AutoResize = True 
> and the Width of which is the same like Column.Width.
> - Then read the resulting Height and give it to Table.Row.Height.
>
> What do you think?
>
> Rolf
>
>
>   
Hi rolf,

Your suggestions worked fine, see the picture (I'm doing my drug 
prescribing section at the moment)

Using  the grids richtext property and the table.font.width to keep 
track of the widest of each column makes it easy to set the column 
widths, and row heights as per the picture.
It would also be easy to put in more sophisticated handling of anomalous 
widths to keep a very long column text from pushing out the width to an 
unreasonable size compared to the general column width.

thanks again

Richard

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sample_grid_rows.png
Type: image/png
Size: 24717 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20120601/df2749ed/attachment.png>


More information about the User mailing list