function TComboRecord.Selected: string; begin Result := FieldValues[ItemSelected]; end;
procedure PopulateComboData(Rows: cardinal); var RowI: cardinal; i: cardinal; ComR: TComboRecord; begin for RowI := 1 to Rows do begin Setlength(ComR.FieldValues, random(5) + 1); for i := 0 to length(ComR.FieldValues) - 1 do ComR.FieldValues[i] := inttostr(random(64000)); ComR.ItemSelected := 0; ComboData.Add(ComR); end; end;
function TComboBoxCell.GetComboData: TComboRecord; begin FComboData.ItemSelected := ItemIndex; Result := FComboData; end;
procedure TComboBoxCell.SetComboData(const Value: TComboRecord); var s: string; begin FComboData := Value; Items.Clear; for s in Value.FieldValues do Items.Add(s); ItemIndex := Value.ItemSelected; end;
procedure TComboBoxCell.SetData(const Value: TValue); begin inherited; ComboData := Value.AsType<TComboRecord> end;
function TComboColumn.CreateCellControl: TStyledControl; begin Result := TComboBoxCell.Create(Self); TComboBoxCell(Result).OnChange := DoComboChanged; end;
procedure TComboColumn.DoComboChanged(Sender: TObject); var P: TPointF; LGrid: TComboExtendedGrid; begin LGrid := Grid; if not Assigned(LGrid) then Exit; if FUpdateColumn then Exit; if FDisableChange then Exit; P := StringToPoint(TFmxObject(Sender).TagString); LGrid.SetValue(Trunc(P.X), Trunc(P.Y), TValue.From<TComboRecord>(TComboBoxCell(Sender).ComboData)); if Assigned(LGrid.FOnEditingDone) then LGrid.FOnEditingDone(Grid, Trunc(P.X), Trunc(P.Y)); end;
function TComboColumn.Grid: TComboExtendedGrid; var P: TFmxObject; begin Result := nil; P := Parent; while Assigned(P) do begin if P is TCustomGrid then begin Result := TComboExtendedGrid(P); Exit; end; P := P.Parent; end; end;
procedure TComboExtendedGrid.SetValue(Col, Row: integer; const Value: TValue); begin inherited;
procedure TForm1.Grid2GetValue(Sender: TObject; const Col, Row: integer; var Value: TValue); begin case Col of 6 { Combo Column Number } : Value := TValue.From<TComboRecord>(ComboData[Row]) end; end;
procedure TForm1.Grid2SetValue(Sender: TObject; const Col, Row: integer; const Value: TValue); begin case Col of 6 { Combo Column Number } : ShowMessage(Value.AsType<TComboRecord>.Selected); end; end;
Do not forget to pass changes (if you need) to ComboData list. The current handlers will not do this for you. I prefer making this in Grid2SetValue event handler.
This looks very promising and comprehensive (way above my ability to write, but readable to me). Will accept as answer when I've had a chance to test it thoroughly. Thanks! – nolaspeaker Oct 4 '15 at 18:34 Let's get this straight. I got it all sorted now. There are 2 things I changed for D10. 1. StringToPoint is now in FMX.Utils 2. s := Value.AsType<TComboRecord>.Selected; in Grid1.SetValue causes an AV in D10. I have replaced that with ComR := Value.AsType<TComboRecord>; if ComR.ItemSelected > -1 then s := ComR.FieldValues[ComR.ItemSelected]; for D10. Then it works just fine. – nolaspeaker Oct 11 '15 at 18:20 I also added 3. type TComboColumn = class(TColumn) private FUpdateColumn: Boolean; FDisableChange: Boolean; as compared to the XE7 version that I got working first. – nolaspeaker Oct 11 '15 at 18:38 @nolaspeaker You can try to write ApplyStyle and ApplyStyling procedures for setting the presentation (font color, font size etc.) of the cell controls as well. It is very comfortable to pass necessary flags using TComboRecord as a container. – asd-tm Oct 11 '15 at 18:51 1 I have no experience with ApplyStyle and Applystyling, but more importantly, my next question is about the grid display. The currently selected value of the combobox is only shown when the cell is actually selected, otherwise the cell just shows (record). Is that a long answer? – nolaspeaker Oct 11 '15 at 18:55
----------------------------------------------
-