Delphi中RzCheckTree从ACCESS中取值

procedure TForm1.FormCreate(Sender: TObject); varI,Y,L:Integer; Bstr,Sustr:string; RootNode,SubNode,SutNode:TTreeNode; begintryADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Password="";Data Source='+ GetCurrentDir + '/db/mydb.mdb;Persist Security Info=True'; ADOConnection1.LoginPrompt:=False; ADOConnection1.Connected:=True; ADOQuery1.Connection:=ADOConnection1; ADOQuery2.Connection:=ADOConnection1; ADOQuery3.Connection:=ADOConnection1; exceptApplication.MessageBox('数据库连接错误','错误',16); Application.Terminate; end; with ADOQuery1 dobeginClose; SQL.Clear; SQL.Add('select distinct Rep_name from Rep_all'); Open; First; for I := 0 to ADOQuery1.RecordCount - 1 do//根节点循环 beginBstr:=ADOQuery1.FieldByName('Rep_name').AsString; //获得根节点名称 RootNode:=RzCheckTree1.Items.Add(nil,Bstr);//创建根节点 with ADOQuery2 dobeginClose; SQL.Clear; SQL.Add('select * from Rep_all where Rep_name='''+ Bstr +''''); //通过根节点查询子节点 Open; First; for Y := 0 to ADOQuery2.RecordCount - 1 do //子节点循环 beginSustr:=FieldByName('Rep_subname').AsString; SubNode:=RzCheckTree1.Items.AddChild(RootNode,FieldByName('Rep_subname').AsString); //创建子节点 with ADOQuery3 dobeginClose; SQL.Clear; SQL.Add('select * from Rep_opt where opt_name=''' + Sustr +''''); Open; First; for L := 0 to ADOQuery3.RecordCount - 1 do//第2个子节点 beginSutNode:=RzCheckTree1.Items.AddChild(SubNode,FieldByName('Rep_opt').AsString); Next; //第2个子节点 end; end; Next; //子节点 end; end; Next; //根节点 end; end; end;

二、获取用户选择的值LqP码友部落
LqP码友部落
 LqP码友部落

1.uses commctrl; 2.按钮代码 procedure TForm1.quzhiClick(Sender: TObject); varQnode:TTreeNode; Qtvi:TTVItem; beginMemo1.Lines.Clear; //先清除Memo1中的数据 for Qnode in RzCheckTree1.Items dobeginQtvi.mask:= TVIF_STATE; //or code 8 Qtvi.hItem:=Qnode.ItemId; TreeView_GetItem(RzCheckTree1.Handle,Qtvi); if Qtvi.state and $2000=$2000 thenbeginMemo1.Lines.Add(Qnode.Text); //获得用户选择值写入到Memo1中 end; end; end;LqP码友部落