Forum > Win32/64

Question about TreeView and ImageList

(1/1)

jma_sp:
When we create a form with a TreeView and edit content of TreeView in desing time, asigning images to TreeView from ImageList where this link betwen images and tree is stored? and if we savetofile the tree and newly loadfromfile images don´t restore association of images with tree items (same content and structure in this case). There is a way to save also index images in savetofile not only names with tab? or where this association is stored when form is saved?

Thanks.

ausdigi:
The settings you change in the designer should be saved in the .lfm (Lazarus ForM) file. If they aren't there may be a bug.

However I'm not 100% sure I understand what you are doing so it would help if you attached a simple project and then the steps to reproduce the problem from there. I don't have Lazarus on this computer so I can't right now test what I think you are doing.

LA.Center:
TreeView.SaveToFile simple saves the text to a file, when you use LoadFromFile it will only restore the text since imageIndex and SelectedIndex are not stored.

If you don't need your Tree content to be human readable I suggest that you save it in binary format like this:


--- Code: ---procedure saveTreeToFile(filename: string);
var
  f: TFileStream;
begin
  f := TFileStream.Create('somefile', fmCreate);
  f.WriteComponent(treeview.Items);
  f.Free;
end;


procedure loadTreeFromFile(filename: string);
var
  f: TFileStream;
begin
  f := TFileStream.Create('somefile', fmOpenRead);
  f.ReadComponent(treeview.Items);
  f.Free;
end;
--- End code ---

I have not tested above sample, you may have to adjust a bit, but this is the way to go if you want to save all information to a binary file.

make sure that you clear all items in the treeview before you load something.

Hope this helps

jma_sp:
OK plusplus, thanks, it helps to hide the information in simple text format, an enhancement to the program.

ausdigi, you are right, the images are stored in files when in design. I have looking the files contents.

What i have been tried is to assign images to the nodes in the treeview an runtime and use a source of information for select dinamicaly the image from previously stored imagelit1.

For this i was in the right direction but forget to associate treeview1 to imagelist1  :-X. Without it nothing happens.

I have assigned the images and used treeview1.beginupdate   treeview.endupdate treeview1.refresh  and treeview.repaint after assigning the images with
    nodo.ImageIndex  nodo.SelectedIndex  nodo.StateIndex

I´m creating a simple phone index in treewiew.

Regards.

Navigation

[0] Message Index

Go to full version