como cargar una tabla en un tTreeVieu
Adjunto codigo, con cortes de control
chao
procedure Tfrmmaestrochecklist.CargaTrv;
var
tnode, tnode0, tnode1, tnode2 : TTreeNode;
begin
Trv.Items.Clear;
tnode := TtreeNode.Create(Trv.Items);
tnode0 := TtreeNode.Create(Trv.Items);
tnode1 := TtreeNode.Create(Trv.Items);
tnode2 := TtreeNode.Create(Trv.Items);
qry.close;
qry.DatabaseName := gv_basedatos;
qry.RequestLive := false;
qry.sql.Clear;
qry.SQL.Add('select seccion from maestrochecklist ');
qry.SQL.Add('group by seccion order by seccion');
qry.Open;
while not qry.eof do
begin
tnode0 := Trv.Items.Add(tnode,qry.fieldbyname('seccion').asstring);
tnode0.ImageIndex := 0;
tnode0.SelectedIndex := 0;
qry0.close;
qry0.DatabaseName := gv_basedatos;
qry0.RequestLive := false;
qry0.sql.Clear;
qry0.SQL.Add('select item from maestrochecklist ');
qry0.SQL.Add('where seccion = :v_sec ');
qry0.SQL.Add('group by item order by item');
qry0.ParamByName('v_sec').asstring := qry.fieldbyname('seccion').asstring;
qry0.Open;
while not qry0.eof do
begin
tnode1 := Trv.Items.AddChild(tnode0,qry0.fieldbyname('item').asstring);
tnode1.ImageIndex := 1;
tnode1.SelectedIndex := 1;
qry1.close;
qry1.DatabaseName := gv_basedatos;
qry1.RequestLive := false;
qry1.sql.Clear;
qry1.SQL.Add('select subitem from maestrochecklist ');
qry1.SQL.Add('where seccion = :v_sec and item = :v_ite');
qry1.SQL.Add('group by subitem order by subitem');
qry1.ParamByName('v_sec').asstring := qry.fieldbyname('seccion').asstring;
qry1.ParamByName('v_ite').asstring := qry0.fieldbyname('item').asstring;
qry1.Open;
while not qry1.eof do
begin
tnode2 := Trv.Items.AddChild(tnode1,qry1.fieldbyname('subitem').asstring);
tnode2.ImageIndex := 2;
tnode2.SelectedIndex := 2;
qry1.Next;
end;
qry1.close;
qry0.Next;
end;
qry0.close;
qry.Next;
end;
qry.close;
Trv.FullExpand;
|