给帖你一段代码,你自己琢磨吧:)
------------------------------------------------------------------
void __fastcall TForm1::FillTreeView()
{
TTreeNode * tn1,*tn2;
ADOQuery1->Close();
ADOQuery1->SQL->Text="select TABLENAME,TABLEDESC,CLASSID,CLASSNAME from sdtable,sdclass where CLASSID=TABLECLASSID order by CLASSID,TABLENAME ";
ADOQuery1->Open();
TreeView1->Items->Clear();
tn1=TreeView1->Items->Add(NULL,"ERP数据表");
AnsiString strTABLENAME,strCLASSID,strCLASSNAME,tmpCLASSID,strTABLEDESC;
tmpCLASSID="ERP数据表";
ADOQuery1->First();
while(!ADOQuery1->Eof){
strTABLENAME=ADOQuery1->FieldByName("TABLENAME")->AsString;
strCLASSID=ADOQuery1->FieldByName("CLASSID")->AsString;
strCLASSNAME=ADOQuery1->FieldByName("CLASSNAME")->AsString;
strTABLEDESC=ADOQuery1->FieldByName("TABLEDESC")->AsString;
if(tmpCLASSID!=strCLASSID){
tn2=TreeView1->Items->AddChild(tn1,strCLASSNAME+" | "+strCLASSID);
tmpCLASSID=strCLASSID;
}
AnsiString s=Format("%-15s <> %s",OPENARRAY(TVarRec,(strTABLENAME,strTABLEDESC)));
TreeView1->Items->AddChild(tn2,s);
ADOQuery1->Next();
}
TreeView1->Selected = TreeView1->Items->Item[0];
TreeView1->Selected->Expand(false);
}
--------------------------------------------------------------------------
如上面那位兄弟说的,帮助有详细说明.你不妨多看一下。