add small icon to virtualtreeview

耗尽温柔 提交于 2019-12-01 12:04:59
balazs

Let's have an image list ImageList1 and assign it to VirtualStringTree1.Images property. Then joining to the previous commenters, before you use FileInfo, assign something to it, like: FileInfo := Sender.GetNodeData(Node), than you can use FileInfo.FileIco. But you should add your icon to the imagelist not in the OnGetImageIndex. You should do it in OnInitNode (if you follow the virtual paradigm, what you should do), than store the index of the added icon in FileInfo. example:

procedure TForm1.VirtualStringTree1InitNode(Sender: TBaseVirtualTree;
  ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
var
  FileInfo: PFileInfoRec;
begin
  FileInfo := Sender.GetNodeData(Node);
  //...
  FileInfo.FileIcoIndex := ImageList1.AddIcon(FileInfo.FileIco);

end;

than in onGetImageIndex:

procedure TMainFrm.VSTGetImageIndex(Sender: TBaseVirtualTree;
  Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex;
  var Ghosted: Boolean; var ImageIndex: Integer);
var
  FileInfo: PFileInfoRec;
begin
  FileInfo := Sender.GetNodeData(Node);
  if Kind in [ikNormal , ikSelected] then
  begin
    if Column = 0 then
    ImageIndex :=FileInfo.FileIcoIndex;
  end;
end;

If it's not adequate, please post more sample code, to enlighten us about your problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!