It's better to use an object name in place of a pointer. That's because a
pointer could reference more than one object on the form. Object names are
unique and so reference only a single object.
Here are a couple of things you might try.
Try #1
=====
For calculating the column widths, replace pointers with object names:
So this calculation with pointers:
OBJECT GET BEST SIZE($Column_pa{$i}->;$Width_best1_l;$Height_best_l)
OBJECT GET BEST SIZE($Header_pa{$i}->;$Width_best2_l;$Height_best_l)
become a calculation with object names:
OBJECT GET BEST SIZE(*;$Column_ta{$i}->;$Width_best1_l;$Height_best_l)
OBJECT GET BEST SIZE(*;$Header_ta{$i}->;$Width_best2_l;$Height_best_l)
Try #2
=====
Also, these 4-lines:
LISTBOX SET COLUMN WIDTH($Column_pa{$i}->;$Width_best_l)
LISTBOX SET COLUMN WIDTH($Header_pa{$i}->;$Width_best_l)
LISTBOX SET COLUMN WIDTH(*;$Header_ta{$i};$Width_best_l)
LISTBOX SET COLUMN WIDTH(*;$Column_ta{$i};$Width_best_l)
can become a single line:
LISTBOX SET COLUMN WIDTH(*;$Column_ta{$i};$Width_best_l)
Try #3
=====
Set the listbox column widths **after** you make SLQ SELECT calls.
See "Displaying the result of an SQL query in a list box” at:
http://doc.4d.com/4Dv16R3/4D/16-R3/Managing-List-Box-Objects.300-3218275.en.html#429187
<http://doc.4d.com/4Dv16R3/4D/16-R3/Managing-List-Box-Objects.300-3218275.en.html#429187>
Note the line which reads, "Each new execution of a SELECT query with the list
box leads to the resetting of the columns…"
> On Sep 15, 2017, at 6:37 PM, bernard--- via 4D_Tech <[email protected]>
> wrote:
>
> Hi all,
>
> I have a form with two listboxes.
> I wrote some code to manage automatic column width (OBJECT GET BEST SIZE,
> LISTBOX SET COLUMN WIDTH).
>
> I build listbox1 with records from Table1 (fill by SQL) ; code for automatic
> width is executed for LB1.
> When I click on a row of LB1, I fill listbox2 with records from TableN
> (always by SQL) ; code for automatic width is executed for LB2.
>
> Why LB1 is redrawn with default width* ?
>
> * I don't understand column width given by 4D : neither leader with, neither
> data width...
>
> I did a new test with automatic width for the two LB : same issue.
>
> Here is the code (simplified) :
> LISTBOX GET
> ARRAYS(Listbox1;$Column_ta;$Header_ta;$Column_pa;$Header_pa;$Col_visible_ba;$Style_pa)
>
> For($i;1;Size of array($Column_pa))
> OBJECT GET BEST SIZE($Column_pa{$i}->;$Width_best1_l;$Height_best_l)
> OBJECT GET BEST SIZE($Header_pa{$i}->;$Width_best2_l;$Height_best_l)
> $Width_best_l:=MTH_Maximum($Width_best1_l;$Width_best2_l)+10
> LISTBOX SET COLUMN WIDTH($Column_pa{$i}->;$Width_best_l)
> LISTBOX SET COLUMN WIDTH($Header_pa{$i}->;$Width_best_l)
> LISTBOX SET COLUMN WIDTH(*;$Header_ta{$i};$Width_best_l)
> LISTBOX SET COLUMN WIDTH(*;$Column_ta{$i};$Width_best_l)
> End for
>
> LISTBOX GET
> ARRAYS(Listbox2;$Column_ta;$Header_ta;$Column_pa;$Header_pa;$Col_visible_ba;$Style_pa)
>
> For($i;1;Size of array($Column_pa))
> OBJECT GET BEST SIZE($Column_pa{$i}->;$Width_best1_l;$Height_best_l)
> OBJECT GET BEST SIZE($Header_pa{$i}->;$Width_best2_l;$Height_best_l)
> $Width_best_l:=MTH_Maximum($Width_best1_l;$Width_best2_l)+10
> LISTBOX SET COLUMN WIDTH($Column_pa{$i}->;$Width_best_l)
> LISTBOX SET COLUMN WIDTH($Header_pa{$i}->;$Width_best_l)
> LISTBOX SET COLUMN WIDTH(*;$Header_ta{$i};$Width_best_l)
> LISTBOX SET COLUMN WIDTH(*;$Column_ta{$i};$Width_best_l)
> End for
>
> I tried also :
>
> $Listbox_t:="Listbox1"
> LISTBOX GET
> ARRAYS(*;"$Listbox_t";$Column_ta;$Header_ta;$Column_pa;$Header_pa;$Col_visible_ba;$Style_pa)
>
> Same behavior.
>
> I see that the second LB takes column width from first LB
> A track : pointer is form.3C.4357.
> I suppose 3C is object ID ; pointers on objects of LB1 and LB2 have same ID...
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> FAQ: http://lists.4d.com/faqnug.html
> Archive: http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub: mailto:[email protected]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************