Recent

Author Topic: [SOLVED] Assigning TStringGrid property to TValueListEditor  (Read 190 times)

egsuh

  • Hero Member
  • *****
  • Posts: 943
I'm trying to apply some properties of TStringGrid to TValueListEditor, as follows. TceNumeric is a descendant of TFrame.

Code: Pascal  [Select][+][-]
  1. constructor TceNumeric.Create(AnOwner: TComponent);
  2. begin
  3.    inherited Create(AnOwner);
  4.  
  5.    ValueListEditor1.Columns[0].SizePriority := 0;
  6.    ValueListEditor1.Columns[0].Width := 150;
  7.    ValueListEditor1.Columns[1].SizePriority := 1;
  8.    ValueListEditor1.AutoFillColumns := True;
  9. end;                    

But this does not work --- it invokes  "List Index (0) out of bounds" error.
Can't I apply the above properties to TValueListEditor?

I'm wondering this because I think TValueListEditor is a descendant of TStringGrid, so it should be simple to use TStringGrid's properties  in TValueListEditor.
« Last Edit: July 07, 2022, 11:18:00 am by egsuh »

wp

  • Hero Member
  • *****
  • Posts: 9908
Re: Assigning TStringGrid property to TValueListEditor
« Reply #1 on: July 07, 2022, 10:26:30 am »
No, you can't. TValueListEditor does not work if the underlying grid has Columns - there is a comment in the sources:
Code: Pascal  [Select][+][-]
  1.   //Don't use Columns.Add, it interferes with setting FixedCols := 1 (it will then insert an extra column)

It seems to be a consequence of the basic issue with LCL grids in which the FixedCol does not count as a TGridColumn.

But why do you need columns at all? To set the width of the 1st column? Simply adjust the DefaultColWidth. Depending on whether the option doKeyColFixed is in the DisplayOptions the first or second column will be adjusted automatically to cover the rest of the control (provided that doAutoColResize is in the DisplayOptions).
« Last Edit: July 07, 2022, 10:33:59 am by wp »

egsuh

  • Hero Member
  • *****
  • Posts: 943
Re: Assigning TStringGrid property to TValueListEditor
« Reply #2 on: July 07, 2022, 11:17:45 am »
Quote
But why do you need columns at all? To set the width of the 1st column? Simply adjust the DefaultColWidth. Depending on whether the option doKeyColFixed is in the DisplayOptions the first or second column will be adjusted automatically to cover the rest of the control (provided that doAutoColResize is in the DisplayOptions).

The reason I was trying to access Columns is that TValueListEditor did not work as I wanted at design time.

Now it works as you mentioned. But the order of setting properties matters.  It finally worked when done in following order (during design time):

   1) FixedCols=1   (Probably I might have missed this in the beginning).
   2) DefaultColWidth=120
   3) doKeyColFixed=True
   4)  doAutoColResize = true

If I check doAutoColResize before doKeyColfixed then the two columns become the same size.  And then the size of Key column is fixed, regardless of DefaultColFixed.

 

TinyPortal © 2005-2018