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
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();
}
}
//---------------------------------------------------------------------------