Recent

Author Topic: Stringgrid & Picklist  (Read 15182 times)

PeterH

  • New Member
  • *
  • Posts: 31
Stringgrid & Picklist
« on: August 29, 2010, 10:28:02 pm »
Hello, I'm using the picklisteditor in a stringgrid to create a comobox style cell editor.
In the OnSelectEditor I choose the piclist editor. This works fine. The editor appears.
Now I want to fill the Picklist with Items to choose from. How is this done?
I found this (http://forum.lazarus.freepascal.org/index.php?topic=7946.0 but I can't get it to work....
I want to add 4 items.
« Last Edit: August 29, 2010, 10:30:10 pm by PeterH »

fabienwang

  • Sr. Member
  • ****
  • Posts: 449
  • Lazarus is the best
    • My blog
Re: Stringgrid & Picklist
« Reply #1 on: August 29, 2010, 11:47:50 pm »
Does yorur StringGrid is editable?
put property Options => goEditing to true
I tried here and it's working.
I'm using Arch Linux.
Known for: CPickSniff, OpenGrabby
Contributed to: LazPaint

PeterH

  • New Member
  • *
  • Posts: 31
Re: Stringgrid & Picklist
« Reply #2 on: August 30, 2010, 10:31:12 am »
The editor becomes visible when I click on the cell.
The problem is in the adding of items to the picklist

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Re: Stringgrid & Picklist
« Reply #3 on: September 11, 2010, 02:02:28 am »
The method described in the link works only if you have added "custom columns"  to your grid, which can be added at design time or at run time, at design time select the grid and in object inspector look for property "columns", press the [...] button and add some columns, for each column you can select a different  "buttonstyle", select cbsPicklist in this case then fill the column's picklist property with the needed values. The described link shows how to fill the picklist at run time.

If you don't want to use "custom columns"  you can use a pick list this way: in event OnSelectEditor write something like this:

Code: [Select]

uses ..., StdCtrls, ....  // don't forget to add StdCtrls unit, needed by TCustomComboBox.

...

procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer;
  var Editor: TWinControl);
begin
  if aCol=2 then begin
    Editor := StringGrid1.EditorByStyle(cbsPickList);
    TCustomComboBox(Editor).Items.CommaText := 'A,B,C,D';
  end;
end;

This will use the picklist editor on column index 2  and user can select A, B, C or D. The other cells will continue to use default string editor.

 

TinyPortal © 2005-2018