添加一个树形列表,单击树形列表的某一项返回对应的id值,在这里考虑用map存放属性列表的名字和id值,可以用map[key] = "Text";将对应数据存入map,然后创建树形列表:
TTreeNode *FirstNode=NULL;
map<int, String>::iterator it = map.begin();
map<int, String>::iterator end = map.end();
FirstNode = DepTree->Items->AddFirst(NULL,it->second);也可以通过AddObject添加对象,注意第一个参数为空
it++;
for (; it != end; ++it)
{
DepTree->Items->AddChild(FirstNode, it->second);//
}
返回选中树形列表id值:
if (Tree->Selected != NULL) {
String str1 = Tree->Selected->Text;//取属性列表选中项名字
map<int, String>::iterator it = map.begin();
map<int, String>::iterator end = map.end();
for (; it != end; ++it)
{
if (it->second == str1) {
ShowMessage(IntToStr(it->first));
}
}
}