FireMonkgyのTGridに画像を表示するにはTImageColumnを使用します。
GridにTImageColumnを追加して、GridのOnGetValueイベントで表示する画像を引数Valueに設定します。
void __fastcall TForm1::Grid1GetValue(TObject *Sender, const int Col, const int Row,
TValue &Value)
{
if (Col == 0)
{
Value = TValue::From(FImages[Row]);
}
}
サンプルプログラム
class TForm1 : public TForm
{
__published: // IDE で管理されるコンポーネント
TGrid *Grid1;
TImageColumn *ImageColumn1;
void __fastcall Grid1GetValue(TObject *Sender, const int Col, const int Row, TValue &Value);
private: // ユーザー宣言
/// 表示する画像
std::vector<TBitmap*> FImages;
public: // ユーザー宣言
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Grid1->RowCount = 5;
//グリッドに表示する画像を読み込む
for (int i = 0; i < 5; ++i)
{
TBitmap* image = new TBitmap();
image->LoadFromFile(Format("C:\\data\\%d.bmp", ARRAYOFCONST((i))));
FImages.push_back(image);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Grid1GetValue(TObject *Sender, const int Col, const int Row,
TValue &Value)
{
if (Col == 0)
{
//グリッドに表示する画像を設定する
Value = TValue::From(FImages[Row]);
}
}