Recent

Author Topic: Why is this combobox misbehaving?  (Read 1457 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 290
Why is this combobox misbehaving?
« on: May 02, 2021, 12:31:46 am »
Windows 10, Laz 2.0.12, svn:64642

I think there's a bug with TComboBox. If you set editor to the spinedit, then everything works as expected. If you set it to the combobox, the box does not cover the full width of the cell. You can see the difference when you look at the two attached images.

Here's the code. The simple project is included as a zip.


Code: Pascal  [Select][+][-]
  1. unit misbehavingcb_main;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.    Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ValEdit, StdCtrls, Grids;
  9.  
  10. type
  11.  
  12.    { TForm1 }
  13.  
  14.    TForm1 = class(TForm)
  15.       ComboBox1: TComboBox;
  16.       SpindEdit1: TSpinEdit;
  17.       ValueListEditor1: TValueListEditor;
  18.       procedure ValueListEditor1SelectEditor(Sender: TObject; aCol,
  19.          aRow: Integer; var Editor: TWinControl);
  20.    private
  21.  
  22.    public
  23.  
  24.    end;
  25.  
  26. var
  27.    Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.lfm}
  32.  
  33. { TForm1 }
  34.  
  35.  
  36. procedure TForm1.ValueListEditor1SelectEditor(Sender: TObject; aCol,
  37.    aRow: Integer; var Editor: TWinControl);
  38. begin
  39.    If (aCol = 1) and (aRow = 1)
  40.    then begin
  41.       //editor := SpinEdit1;   //Uncomment this line and comment the next to see that the code works fine with a TSpinEdit.
  42.        editor := combobox1;
  43.        editor.BoundsRect := valueListeditor1.CellRect(aRow,aCol);
  44.    end;
  45. end;
  46.  
  47. end.
  48.  

On running this, the combobox shows in the right cell (Col:1, Row:1) but it doesn't cover the full width of the cell. If I click on cell (col:0,row:1), then click back on cell (col:1, row:1), the combobox displays as expected.

Any idea why this is misbehaving?
« Last Edit: May 02, 2021, 12:44:20 am by EganSolo »

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Why is this combobox misbehaving?
« Reply #1 on: May 02, 2021, 05:57:39 am »
its the value list editor that is doing it.

if the list editor is the first control to get focused during startup the value reported for the CellRect is short for the width and the next time you click on the cell it then reports the correct value and the combobox is sized property..

 if you place a button or some other control on the form and then set the active form property in the fOrm to point to that instead during startup you will see if another control gets focus first it gives the list editor a chance to complete what its doing and will report the correct Cellrect sizes when you click on the value cell.

 This only seems to happen during initial start of the control if it has focus..


The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Why is this combobox misbehaving?
« Reply #2 on: May 02, 2021, 01:54:06 pm »
I can confirm this observation. But it sounds like a bug. Because the grid already has been painted correctly and thus the grid must know the width of the cell. And it must be something in the ValueListEditor because the same OnSelectEditor handler applied to a TStringGrid works correctly.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Why is this combobox misbehaving?
« Reply #3 on: May 02, 2021, 04:24:21 pm »
in the process of looking at this I found another bug that is caused by a patch (Issue 0029993)

which looks like makes the Display option doKeyColFixed work backwards.

 You turn it on, it allows you to adjust the Key column width, turn it off and it locks it..

I can't be real sure if that patch cause that but looking at this code.
Code: Pascal  [Select][+][-]
  1.       inherited SetFixedRows(1);// don't do FixedRows := 1 here, it wil cause infinite recursion (Issue 0029993)
  2.     end else
  3.       inherited SetFixedRows(0);                                                                
  4.  

 You see there is no attempt to restore the original value, it just sets it to 0 (false);

More to come I am sure.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Why is this combobox misbehaving?
« Reply #4 on: May 02, 2021, 06:48:35 pm »
Apparently if you turn off the "doAutoColResize" in the DisplayOptions the problem goes away, something to do with "AutoFillColumns"


and as a reminder the "doKeyColFixed" appears to be working backwards and is also ignored in various places.

This is of course in the ValEdit file

The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Why is this combobox misbehaving?
« Reply #5 on: May 03, 2021, 11:55:36 pm »
it appears this control needs a little rework..

 For one thing the Method LOADED isn't implemented from what I can see? This causes to the custom grid to complete early and start calling events before the ValueListEditor has completed with its property loading etc...

  Maybe others are using a String Grid variant instead..
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018