Firemonkey: TGrid usage on Embarcadero C++ Builder XE3

后端 未结 3 476
余生分开走
余生分开走 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:22

    In order to solve your problem, redefine the TCheckCell class in the following way:

    #include 
    #include 
    
    class CheckCellClass:public TCheckCell
    {
    public:
     __fastcall virtual CheckCellClass(System::Classes::TComponent*AOwner):TCheckCell(AOwner)
     {
     };
    
     virtual System::Rtti::TValue __fastcall GetData(void)
     {
      return TValue::From(this->IsChecked);
     };
    
     virtual void __fastcall SetData(const TValue&Value)
     {
      TValue V(Value);
      this->IsChecked=V.AsBoolean();
     };
    };
    
    //Redifine TCheckColumn class
    class CheckColumnClass:public TCheckColumn
    {
    private:
     virtual Fmx::Controls::TStyledControl*__fastcall CreateCellControl(void)
     {
      CheckCellClass*Cell=new CheckCellClass(this);
      Cell->OnChange     =&(this->DoCheckChanged);
      return Cell;
     };
    
    public:
    __fastcall CheckColumnClass(System::Classes::TComponent*AOwner):TCheckColumn(AOwner)
     {
     };
    };
    
    //global Data for Save curent State Cell
    
    boost::dynamic_bitsetFullDiscreteInputs;
    
    Add To Grid In Constuctor
     FullDiscreteInputs.resize(100);
     DiscreteInputsGrid->RowCount=FullDiscreteInputs.size();    
     CheckColumnClass* DiscreteInPutsCheckColumn        =new CheckColumnClass(DiscreteInputsGrid);
     DiscreteInputsGrid->AddObject(CoilsCheckColumn);
    
    void __fastcall TForm1::DiscreteInputsGridGetValue(TObject*Sender, const int Col, const int Row,TValue&Value)
    {
     //...
    
     if(DiscreteInputsGrid->ColumnByIndex(Col)==DiscreteInPutsCheckColumn)
     {
     Value=TValue::From(FullDiscreteInputs[Row]);
     }
     //...
    }
    
    //---------------------------------------------------------------------------
    void __fastcall TForm1::DiscreteInputsGridSetValue(TObject*Sender, const int Col, const int Row, const TValue&Value)
    {
     TValue V(Value);
     if(DiscreteInputsGrid->ColumnByIndex(Col)==DiscreteInPutsCheckColumn)
     {
     FullDiscreteInputs[Row]=V.AsBoolean();
     }
    }
    //---------------------------------------------------------------------------
    

提交回复
热议问题