Recent

Author Topic: StringGrid Column Stretching  (Read 1143 times)

Lamb3234

  • New Member
  • *
  • Posts: 16
StringGrid Column Stretching
« on: December 07, 2019, 05:34:01 pm »
Hello,

I have 4 columns in my StringGrid. The user can resize the width of the columns at runtime by dragging the sides of the columns horizontally. How do I make it so that the columns are docked to the right of the StringGrid, so when the user decreases the width of a column, no white space appears to the right of the 4 columns, and when the user increases the width of a column, no horizontal scroll bar appears and the rightmost column remains docked to the right edge of the StringGrid.

I hope this is explained well enough and I would appreciate any advice!
« Last Edit: December 07, 2019, 08:51:09 pm by Lamb3234 »

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: StringGrid Column Stretching
« Reply #1 on: December 07, 2019, 06:30:51 pm »
Maybe this:

Set AutoFillColumns to true. Then using the Columns property editor create as many columns as you need. Select each column in the object tree above the object inspector and set their SizePriority to 0. Now decide which column will be stretched in width such that the entire clientwidth of the grid is filled by columns -- set the SizePriority of this column to 1.

Lamb3234

  • New Member
  • *
  • Posts: 16
Re: StringGrid Column Stretching
« Reply #2 on: December 07, 2019, 06:46:26 pm »
Thank you wp, that's exactly what I need. Solved.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [SOLVED]StringGrid Column Stretching
« Reply #3 on: December 07, 2019, 07:03:37 pm »

Lamb3234

  • New Member
  • *
  • Posts: 16
Re: [SOLVED]StringGrid Column Stretching
« Reply #4 on: December 07, 2019, 07:41:19 pm »
I added a chapter about this topic to the Grids wiki article: https://wiki.lazarus.freepascal.org/Grids_Reference_Page#Avoiding_the_empty_space_at_the_right_of_the_last_column

I just set all of the column SizePriority's to 0 and it works quite well. It's just a shame it's not possible to set a minimum column width, because the user might accidentally resize a column to 0, and not be able to see it.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: [SOLVED]StringGrid Column Stretching
« Reply #5 on: December 07, 2019, 08:05:53 pm »
Hmmm... The grid seems to be prepared for that. There is a MinSize and MaxSize property for each column, and they are evaluated in the GetAutoFillColumnInfo method along with the SizePriority -- but they are not used in any way else... Maybe forgotten, maybe too difficult, maybe nobody asked for it so far...?

 

TinyPortal © 2005-2018