Firemonkey: TGrid usage on Embarcadero C++ Builder XE3

后端 未结 3 466
余生分开走
余生分开走 2021-01-25 04:37

I\'m try to build a tool that reads data from a database and displays it as a table using a TGrid in Firemonkey. I need to use different types of columns like TCheckColumn and T

3条回答
  •  时光说笑
    2021-01-25 05:04

    I can't give C++ code but a Delphi example should be easy enough to translate.

    You get and set all cell values the same way, by listening for the OnGetData and OnSetData events, get take/give values of type TValue (XE3 and later). It's just a case of returning the appropriate type in the TValue:

    uses System.RTTI;
    
    procedure Form1.Grid1GetValue(Sender: TObject;const Col, Row: Integer;var Value: TValue);
    begin
      if Col = 1 then
        Value := TValue.From(1)
      else if Col = 2 then
        Value := TValue.From('Hello')
      else if Col = 3 then
        Value := Tvalue.From(1.0);
    end;
    
    procedure Form1.Grid1SetValue(Sender: TObject;const Col, Row: Integer;const Value: TValue);
    begin
      if Col = 1 then
        I := Value.As
      else if Col = 2 then
        St := Value.As
      else if Col = 3 then
        Si := Value.As;
    end;
    

    As far as I can tell a popup menu can't accept or give data.

提交回复
热议问题