Jump to content

UniGui UniTreeView Populated by UniMenuItems, item count 0


Franco Grech
 Share

Recommended Posts

Good day everyone

I am building an app where i have to populate a UniTreeView from UniMenuItems in code.

ItemTree is a UniTreeView

ItemList Is a TList of UniMenuItems

Code :

procedure TdtfrmFolderBuilder.RefreshFolder;
var
 xItem : TCostumeMenuItem;
 function GetParent(AParentID : integer) : TCostumeMenuItem;
 var
   xI :Integer;
 begin
     for xI := 0 to ItemList.Count -1 do
     begin
         if ItemList[xI].ITEM_ID = AParentID then
         begin
           Result := ItemList[xI];
           exit;
         end;
     end;
     Result := TCostumeMenuItem(nil);
 end;
 procedure PrepareTreeView;
 begin
   if Assigned(ItemTree) then begin
     ItemTree.Free;
     lst1.Items.Add('DDes');
   end;
   ItemTree := TUniTreeView.Create(Self);
   lst1.Items.Add('Created');
   ItemTree.OnClick := ItemTreeClick;
   //ItemTree.OnAjaxEvent := ItemTreeAjax;
   lst1.Items.Add('Events Added');
   ItemTree.Items.Clear;
   lst1.Items.Add('Items Cleared');
 end;
begin
  PrepareTreeView;
  ItemTree.BeginUpdate;
  fdtrnsctn_buildfulltree.StartTransaction;
  fdqry_buildfulltree.Open;
  ItemList.Clear;
  unmntms_folder.Items.Clear;


  while fdqry_buildfulltree.Eof = false do
  begin
    xItem := TCostumeMenuItem.Create(Self);
    xItem.ID := fdqry_buildfulltree.FieldByName('O_ID').AsInteger;
    xItem.Tag := xItem.ID;
    xItem.HID := fdqry_buildfulltree.FieldByName('O_HID').AsInteger;
    xItem.ITEM_ID := fdqry_buildfulltree.FieldByName('O_ITEM_ID').AsInteger;
    xItem.PARENT_ID := fdqry_buildfulltree.FieldByName('O_PARENT_ITEM_ID').AsInteger;
    xItem.ItemName := fdqry_buildfulltree.FieldByName('finalname').AsString;
    xItem.Caption := xItem.ItemName;
    xItem.Name := 'btn_'  + xItem.ID.ToString;
    ItemList.Add(xItem);
    fdqry_buildfulltree.Next;
  end;
  fdqry_buildfulltree.Close;
  fdtrnsctn_buildfulltree.Commit;

  for xItem in ItemList do
  begin
     if xItem.PARENT_ID = 0 then
     begin
       unmntms_folder.Items.Add(xItem);
       //unpmn_detail1.Items.Add(xItem);
     end
     else
     begin
       GetParent(xItem.PARENT_ID).Add(xItem);
     end;
  end;
  lst1.Items.Add('Finished Vir Tree Build Totale  : ' +unmntms_folder.Items.Count.ToString);
  ItemTree.Align := alLeft;
  ItemTree.Parent := Self;
  ItemTree.Width := 350;
  ItemTree.SourceMenu := unmntms_folder;
  lst1.Items.Add('Source menu added');
  ItemTree.EndUpdate;
  lst1.Items.Add('Item count in SOurce : ' + unmntms_folder.Items.Count.ToString + ' Count in View : ' + ItemTree.Items.Count.ToString);

end;

 

The problem is after i add the source menu ItemTree.items.count returning a 0 i check in both debug mode and its a 0 however i can see the items in runtime.

Why is this happening and how i can fix this issue.
Thanks for any kind of help

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.

 Share

×
×
  • Create New...