Fórum Preencher treeview com plano de contas #344488
14/08/2007
0
Pessoal tenho a função abaixo que me da determinado plano de contas em um treeview só que o mesmo me mostra tudo certinho co excessão dos nós nos niveis ... alguem poderia me ajudar :
function NivelHierarquico( const s : ShortString ) : Byte;
begin
Result := Length( s ) - Length( StringReplace( s, ´.´, ´´, [rfReplaceAll]));
end;
var NivelAtual, NovoNivel, i : Byte;
Descricao : ShortString;
NovoNo : TTreeNode;
begin
NivelAtual := NivelHierarquico( IBQUERY1.Fields[1].AsString );
repeat
Descricao := IBQUERY1.Fields[1].AsString + ´ - ´ + IBQUERY1.Fields[0].AsString + ´ R$´;
NovoNivel := NivelHierarquico( IBQUERY1.Fields[1].AsString );
if NovoNivel = NivelAtual then
begin
NovoNo := tv.Items.AddChild( Pai, Descricao );
NovoNo.ImageIndex := NivelAtual * 2;
NovoNo.SelectedIndex := NivelAtual * 2;
end
else
begin
if ( NovoNivel < NivelAtual ) then
begin
for i := 1 to NivelAtual - NovoNivel do
Pai := Pai.Parent
end
else
begin
Pai := NovoNo;
end;
PreencherTreeView( IBQUERY1, tv, Pai );
end;
IBQUERY1.Next;
Application.ProcessMessages;
until IBQUERY1.EOF;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
ibquery1.open;
try
PreencherTreeView(ibquery1,treeview1,nil);
except
end;
end;
function NivelHierarquico( const s : ShortString ) : Byte;
begin
Result := Length( s ) - Length( StringReplace( s, ´.´, ´´, [rfReplaceAll]));
end;
var NivelAtual, NovoNivel, i : Byte;
Descricao : ShortString;
NovoNo : TTreeNode;
begin
NivelAtual := NivelHierarquico( IBQUERY1.Fields[1].AsString );
repeat
Descricao := IBQUERY1.Fields[1].AsString + ´ - ´ + IBQUERY1.Fields[0].AsString + ´ R$´;
NovoNivel := NivelHierarquico( IBQUERY1.Fields[1].AsString );
if NovoNivel = NivelAtual then
begin
NovoNo := tv.Items.AddChild( Pai, Descricao );
NovoNo.ImageIndex := NivelAtual * 2;
NovoNo.SelectedIndex := NivelAtual * 2;
end
else
begin
if ( NovoNivel < NivelAtual ) then
begin
for i := 1 to NivelAtual - NovoNivel do
Pai := Pai.Parent
end
else
begin
Pai := NovoNo;
end;
PreencherTreeView( IBQUERY1, tv, Pai );
end;
IBQUERY1.Next;
Application.ProcessMessages;
until IBQUERY1.EOF;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
ibquery1.open;
try
PreencherTreeView(ibquery1,treeview1,nil);
except
end;
end;
Jrduran
Curtir tópico
+ 0
Responder
Posts
14/08/2007
Ricardo_ascii
http://forum.clubedelphi.net/viewtopic.php?t=84558&highlight=treeview
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)