Add a TCombobox Column to a Firemonkey TGrid

后端 未结 2 1669
不知归路
不知归路 2021-01-23 06:59

This question appears to have been answered already, possibly by MonkeyStyler/Mike Sutton, however, as I am using Delphi 10 Seattle, provided code and guides don\'t wor

2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-23 07:24

    Here is the easy way to add a Combobox to a FMX TGrid. Granted, this solution has the same items in every combo, but that's all I can achieve right now.

    type
      TComboColumn = class(TPopupColumn)
        function CreateCellControl: TStyledControl; override;
      end;
    

    ...

    function TComboColumn.CreateCellControl: TStyledControl;
    var
      ComR: TComboRecord;
      i: Integer;
    begin
       Result := TComboBoxCell.Create(self);
       // now they all have the same drop-down values
       ComR := frmMain.ComboData[0];
       for i := 0 to Length(ComR.FieldValues) do
         TComboBoxCell(Result).Items.Add(ComR.FieldValues[i]);
    end
    

    ... And just for continuity

    procedure TfrmMain.FormCreate(Sender: TObject);
    begin
       AGrid := TComboExtendedGrid.Create(Self);
       AGrid.Parent := Self;
       AGrid.Align := TAlignLayout.Client;
       AGrid.Options := AGrid.Options + [TGridOption.AlwaysShowEditor];
       AGrid.OnGetValue := AGridGetValue;
       AGrid.OnSetValue := AGridSetValue;
       AGrid.RowCount := 5;
    
       ComboData := TList.Create;
       PopulateComboData(AGrid.RowCount);
    
       CCColumn := TComboColumn.Create(AGrid);
       CCColumn.Parent := AGrid;
       CCColumn.Header := 'Combohere';   
    end;
    

提交回复
热议问题