|
CPP file----------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBoxMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TCheckBox* cbCheck = dynamic_cast<TCheckBox*>(Sender);
cbCheck->Checked = !cbCheck->Checked;
Checked[StrToInt(cbCheck->Caption)-1] = cbCheck->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{
tmp=StringGrid1->TopRow-1;
for(int x=0;x<StringGrid1->VisibleRowCount;x++){
t=new TCheckBox(this);
StringGrid1->Objects[StringGrid1->TopRow+x][0] = t;
t->Parent = StringGrid1;
t->BoundsRect = StringGrid1->CellRect(1,StringGrid1->TopRow + x);
t->OnMouseUp = CheckBoxMouseUp;
t->Caption = IntToStr(StringGrid1->TopRow + x);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1TopLeftChanged(TObject *Sender)
{
tmp=StringGrid1->TopRow-1;
for(int x=0;x<StringGrid1->VisibleRowCount;x++){
t=new TCheckBox(this);
StringGrid1->Objects[StringGrid1->TopRow+x][0] = t;
t->Parent = StringGrid1;
t->BoundsRect = StringGrid1->CellRect(1,StringGrid1->TopRow+x);
t->OnMouseUp = CheckBoxMouseUp;
t->Caption = IntToStr(StringGrid1->TopRow+x);
t->Checked=Checked[StrToInt(t->Caption)-1];
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
delete t;
}
//---------------------------------------------------------------------------
H file------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TStringGrid *StringGrid1;
void __fastcall StringGrid1TopLeftChanged(TObject *Sender);
void __fastcall CheckBoxMouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall FormShow(TObject *Sender);
void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
private: // User declarations
public: // User declarations
int tmp;
TCheckBox *t;
bool Checked[100];
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
|