我正在使用 Embarcadero 的 C++ Builder XE8。我有一个 ListView 并正在动态添加列及其项目。我需要一个图像列表,因为我想使用 (ListItem->SubItemImages[0] = i;) 将图像添加到第二列
似乎通过添加此图像列表,默认情况下 C++ Builder 认为主列也需要图像,因此默认情况下它将我的图像列表的第 0 个元素附加到该列中的所有项目。我不希望这种情况发生。相反,在“ID”列下,我只想要 ID 而不是任何图像。我怎样才能做到这一点?
我的代码:
void __fastcall TForm1::FormCreate(TObject *Sender)
{
const string firstName[] = {"Snowball", "Scavies", "Tinkerbell", "Fido", "Garfield", "Kobe"};
const string lastName[] = {"M", "E", "O", "W", "W", "W"};
TListColumn *NewColumn;
TListItem *ListItem;
TListView *ListView = ListView1;
ListView->SmallImages = ImageList1;
ListView->ViewStyle = vsReport;
NewColumn = ListView->Columns->Add();
NewColumn->Caption = "ID";
NewColumn = ListView->Columns->Add();
NewColumn->Caption = "Node";
NewColumn = ListView->Columns->Add();
NewColumn->Caption = "First";
for (int i = 0; i < sizeof( firstName ) / sizeof( firstName[0] ); i++)
{
char buffer[3];
itoa(i,buffer,10);
ListItem = ListView->Items->Add();
ListItem->Caption = buffer;
ListItem->SubItems->Add(firstName[i].c_str());
ListItem->SubItems->Add(lastName[i].c_str());
ListItem->SubItemImages[0] = i;
//ListItem->ImageIndex = NULL;
}
}