Jump to content

Refreshing an UniTreeMenu


RaoulW

Recommended Posts

Hi,

Newbie user and looks great!

I'm tring to update a TUniTreeMenu inside the event handler of a menu item. When I do this, the entire menu is ducplicated. I have tried:

    UniTreeMenu1.BeginUpdate;
    UniTreeMenu1.SourceMenu := nil;

   MyMenuItems.Clear;

etc.

MyMenuItems is a sub menu. 

 

What am I doing wrong?

 

Link to comment
Share on other sites

7 hours ago, RaoulW said:

I'm tring to update a TUniTreeMenu inside the event handler of a menu item. When I do this, the entire menu is ducplicated. I have tried:

    UniTreeMenu1.BeginUpdate;
    UniTreeMenu1.SourceMenu := nil;

   MyMenuItems.Clear;

etc.

MyMenuItems is a sub menu. 

Hello,

Please provide more details.

Link to comment
Share on other sites

Hi, 

I believe there is some gap or at least handled different with the html menu compared to native delphi.

If you skip the following 4 lines (2 before your updates and 2 after your updates) the menu is updated correct. So changes are not updated correctly on the UniTreeMenu1 when using .BeginUpdate / .EndUpdate (So at least these lines mustn't be used for the menu to be updated correctly.



    UniTreeMenu1.BeginUpdate;
    UniTreeMenu1.SourceMenu := nil;

// All other code...

  UniTreeMenu1.EndUpdate;
  UniTreeMenu1.SourceMenu := UniMenuItems1;

 

Link to comment
Share on other sites

Hmm ok, the frist two deal with hiding existing items and not adding them.

I tried the last option but that removes all menu items. I only need to remove or add to a certain subment. No idea how to do that in JS...

 

Thanks,

Link to comment
Share on other sites

Hi,

You must delete each item:

 

    I := UniTreeMenu1.Items.Count-1;

    while(I > 0) do
      begin
        UniTreeMenu1.Items.Delete(UniTreeMenu1.Items.Item[I]);
        I := UniTreeMenu1.Items.Count-1;
        If(I = 0)then
          UniTreeMenu1.Items.Delete(UniTreeMenu1.Items.Item[0]);
      end;

Link to comment
Share on other sites

Hi,

 

 

Thanks for the help. Unfortunately it does not help. I have to re-create a submenu so I changed your example to:

 

    for i := SubMenu.Count-1 downto 0 do
    begin
      for j := SubMenu[i].Count-1 downto 0 do
         SubMenu[i].Delete(j);
      SubMenu.Delete(i);
    end;

 

But that results in the entire menu dissapearing. Using the BeginUpdate and/or SourceMenu := 0 has no effect, the menu stays blank.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...