哪位好人,能献点源代码(0分)

  • 主题发起人 主题发起人 wangchengwu
  • 开始时间 开始时间
W

wangchengwu

Unregistered / Unconfirmed
GUEST, unregistred user!
哪位好人,能献点源代码

我有两个数据表,一个年级表grade,有字段id_grade(年级编号),grade(年级名称),另一个班级表class,有字段id_class(班级编号),class(班级名称),id_grade(年级编号),


我想在窗口左侧放一个treeview显示年级表,在窗口的右侧放一个DBGRID,两个edit控件,


请问如何实现点左侧的treeview的节点,显示已有年级的班级,并可对该年级有添加新的班级功能,
如何实现?


代码如下:




procedure TForm1.FormCreate(Sender: TObject);
var
mynode:ttreenode;
begin
ADOConnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+
'area.mdb;Persist Security Info=False';
ADOConnection1.loginprompt:=false;
adoconnection1.connected:=true;
adoquery1.Connection:=ADOConnection1;
mynode:=treeview1.items.add(nil,'书的书号');
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('Select * from grade');
Open;
end;
ADOQuery1.First;
while not ADOQuery1.Eof do
begin
Treeview1.Items.addchild(mynode,ADOQuery1.FieldByName('grade').asstring);
ADOquery1.next;
end;
end;

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
var
id_Grade: String;
begin
id_Grade := Node.Text;
with adoquery2 do
begin
Close;
SQL.Clear;
SQL.Add('Select * from grade');
SQL.Add('where id_grade='''+id_grade+ '''');
Open;
end;
end;

procedure TForm1.TreeView1Click(Sender: TObject);
begin
if not Assigned(TTreeView(Sender).Selected) then Exit;
with adoquery2 do
begin
sql.Text := Format('SELECT * FROM area WHERE id_grade=%s', [QuotedStr(TTreeView(Sender).Selected.Text)]);
try
adoquery2.Open;
except
ShowMessage('不管我的事');
end;
end;
end;

procedure TForm1.TreeView1Expanded(Sender: TObject; Node: TTreeNode);
var
vTreeNode: TTreeNode;
begin
vTreeNode := Node.GetNextSibling;
while Assigned(vTreeNode) do begin
vTreeNode.Collapse(True);
vTreeNode := vTreeNode.GetNextSibling;
end;
vTreeNode := Node.GetPrevSibling;
while Assigned(vTreeNode) do begin
vTreeNode.Collapse(True);
vTreeNode := vTreeNode.GetPrevSibling;
end;
end;
 
能帮我吗?
 
没有高手吗?
 
后退
顶部