Jump to content

Treeview with customized icons and texts


SergioFeitoza

Recommended Posts

Does anyone know of a demo that shows a Tunitreeview that uses customized icons and has the text of nodes and sub-nodes with colors and different letters? I'm trying to do it for days, but I am missing something and does not work. Please check the figure attached. The code I use to construct the navigator (navtree) is

procedure TMainForm.ConstructNavigator;
var
  RawS : RawByteString;
  S, S1, Path, SubS : string;
  sr: TSearchRec;
  Ls : TStringList;
  Txt : TextFile;
  I, iPos, index, groupindex, mainindex : Integer;
  Nd,Nd1 : TUniTreeNode;
  Mt, Mt1 : TUniMenuItem;
  iconfile, groupIconFile, mainIconFile: string;
begin
   sAplicacao := TStringList.Create;
   sDescricao := TStringList.Create;
   sNivel     := TStringList.Create;
   sItem      := TStringList.Create;
   sSubItem   := TStringList.Create;

   Path := UniServerModule.StartPath;

   Nd := NavTree.Items.Add(nil, 'Home');
   Nd.Data := UniTabSheet1;
   mainIconFile :=  Path+'UNITSmy\icons\main.ico';
   mainindex := CreateImageIndex(mainIconFile);
   nd.ImageIndex := mainindex;

   UniTabSheet1.Tag := NativeInt(Nd);
   UniTabSheet1.ImageIndex := mainindex;
   NavTree.Selected := Nd;

   With UniMainModule.qryAplicacao do
   begin
     Open;
     while Not eof do
     begin
        UniMainModule.qryPerfilAplicacao.Close;
        UniMainModule.qryPerfilAplicacao.Params[0].Value := UniMainModule.PERFIL;
        UniMainModule.qryPerfilAplicacao.Params[1].Value := UniMainModule.qryAplicacao.FieldByName('APLICACAO').AsString;
        UniMainModule.qryPerfilAplicacao.Open;

        mainindex := Nisfc.AddIconCls( UniMainModule.qryAplicacao.FieldByName('imagem').AsString );

        if not UniMainModule.qryPerfilAplicacao.IsEmpty then
        begin
//            mainIconFile :=  Path+'UNITSmy\Icons\'+UniMainModule.qryaplicacaoNIVEL.AsString+'.ico';
//            mainindex := CreateImageIndex(mainIconFile);

            if UniMainModule.qryAplicacao.FieldByName('NODE').AsInteger = 0 then
            begin
               Nd := NavTree.Items.Add(nil, UniMainModule.qryaplicacao.FieldByName('DESCRICAO').AsString);
               nd.ImageIndex := mainindex;

               Mt := TUniMenuItem.Create(Self);
               Mt.Caption := UniMainModule.qryAplicacao.FieldByName('DESCRICAO').AsString;
               Mt.ImageIndex := mainindex;
            end
            else
            begin
               Nd1 := NavTree.Items.Add(Nd, UniMainModule.qryAplicacao.FieldByName('DESCRICAO').AsString);
               nd1.ImageIndex := mainindex;
               sDescricao.Add( UniMainModule.qryAplicacao.FieldByName('DESCRICAO').AsString );
               sAplicacao.Add( UniMainModule.qryAplicacao.FieldByName('NIVEL').AsString+'-'+UniMainModule.qryAplicacao.FieldByName('APLICACAO').AsString );
               sNivel.Add( UniMainModule.qryAplicacao.FieldByName('NIVEL').AsString );
               nd1.Tag := UniMainModule.qryAplicacao.FieldByName('NIVEL').AsInteger;

               sItem.Add( UniMainModule.qryAplicacao.FieldByName('item').AsString );
               sSubItem.Add( UniMainModule.qryAplicacao.FieldByName('subItem').AsString );

               Mt1 := TUniMenuItem.Create(Self);
               Mt1.Caption := UniMainModule.qryAplicacao.FieldByName('DESCRICAO').AsString;
               Mt1.ImageIndex := mainindex;
               Mt1.OnClick := Navigate1Click;
               Mt1.Tag := UniInteger(Nd1);
               Mt.Add(Mt1);
            end;
         end;
           Next;
     end;
   end;
end;

TTuniTreeViewIcons.png

Link to comment
Share on other sites

Thank you  very much Abaksoft and Sherzod

It works well. Now I will try to see about what I am doing wrong about icons

Also I am trying to insert ad event in such a way that when I pass the mouse over the tree node I make visible a figure in the middle of the form

Thanks again

Link to comment
Share on other sites

4 hours ago, SergioFeitoza said:

Now I will try to see about what I am doing wrong about icons

Also I am trying to insert ad event in such a way that when I pass the mouse over the tree node I make visible a figure in the middle of the form

Hello,

If this is an issue, make a simple testcase for check.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...