Jump to content

NestedList


RobYost

Recommended Posts

if I add code to the form show I am able to add subItems

procedure TMainmForm.UnimFormShow(Sender: TObject);
var
  n1, n2, n3: TUniTreeNode;
begin
  n1 := nl1.Items.Add(nil, '11111');
  n2 := nl1.Items.Add(nil, '22222');
  n3 := nl1.Items.Add(nil, '33333');

  nl1.Items.Add(n1, 'aaaa');
  nl1.Items.Add(n2, 'bbbb');
  nl1.Items.Add(n3, 'cccc');
end;

Clicking on 1 goes to a; 2 goes to b etc.

 

but if I put the very same code in a button

procedure TMainmForm.btn1Click(Sender: TObject);
var
  n1, n2, n3: TUniTreeNode;
begin
  n1 := nl1.Items.Add(nil, '11111');
  n2 := nl1.Items.Add(nil, '22222');
  n3 := nl1.Items.Add(nil, '33333');

  nl1.Items.Add(n1, 'aaaa');
  nl1.Items.Add(n2, 'bbbb');
  nl1.Items.Add(n3, 'cccc');
end;

clicking on 1 goes to a, but clicking on 2 and 3 trigger OnLeafClick and have no subitems

 

Link to comment
Share on other sites

Hi,

 

Which build are you using ?! I couldn't reproduce this issue.

 

But you can try to use BeginUpdate, EndUpdate methods:

var
  n1, n2, n3: TUniTreeNode;
begin
  nl1.BeginUpdate;
  n1 := nl1.Items.Add(nil, '11111');
  n2 := nl1.Items.Add(nil, '22222');
  n3 := nl1.Items.Add(nil, '33333');

  nl1.Items.Add(n1, 'aaaa');
  nl1.Items.Add(n2, 'bbbb');
  nl1.Items.Add(n3, 'cccc');
  nl1.EndUpdate;
end;

Best regards,

Link to comment
Share on other sites

I have attached the whole test project but this is the main code.

unit Mainm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics,
  Controls, Forms, uniGUITypes, uniGUIAbstractClasses,
  uniGUIClasses, uniGUImClasses, uniGUIRegClasses, uniGUIForm, uniGUImForm, uniGUImJSForm, uniGUIBaseClasses, uniTreeView, unimNestedList,
  uniButton, unimButton;

type
  TMainmForm = class(TUnimForm)
    nl1: TUnimNestedList;
    btn1: TUnimButton;
    procedure btn1Click(Sender: TObject);
    procedure UnimFormShow(Sender: TObject);
    procedure nl1LeafClick(Sender: TObject);
  private
  public
    { Public declarations }
  end;

function MainmForm: TMainmForm;

implementation

{$R *.dfm}

uses
  uniGUIVars, MainModule, uniGUIApplication;

function MainmForm: TMainmForm;
begin
  Result := TMainmForm(UniMainModule.GetFormInstance(TMainmForm));
end;

procedure TMainmForm.nl1LeafClick(Sender: TObject);
begin
  MessageDlg('Leaf Clicked', mtInformation, [mbOK]);
end;

procedure addItems(nl: TUnimNestedList);
var
  n1, n2, n3: TUniTreeNode;
begin
  n1 := nl.Items.Add(nil, '11111');
  n2 := nl.Items.Add(nil, '22222');
  n3 := nl.Items.Add(nil, '33333');

  nl.Items.Add(n1, 'aaaa');
  nl.Items.Add(n2, 'bbbb');
  nl.Items.Add(n3, 'cccc');
end;

procedure TMainmForm.btn1Click(Sender: TObject);
begin;
  // only the first item of the list when clicked goes to its subitem.
  addItems(nl1);
end;

procedure TMainmForm.UnimFormShow(Sender: TObject);
begin
  // Uncomment below and you will see it works correctly
  // addItems(nl1);
end;

initialization

RegisterAppFormClass(TMainmForm);

end.
Link to comment
Share on other sites

But you can try to use BeginUpdate, EndUpdate methods:

var
  n1, n2, n3: TUniTreeNode;
begin
  nl1.BeginUpdate;
  n1 := nl1.Items.Add(nil, '11111');
  n2 := nl1.Items.Add(nil, '22222');
  n3 := nl1.Items.Add(nil, '33333');

  nl1.Items.Add(n1, 'aaaa');
  nl1.Items.Add(n2, 'bbbb');
  nl1.Items.Add(n3, 'cccc');
  nl1.EndUpdate;
end;
Link to comment
Share on other sites

I tried that, but it made no difference.

 

 

But you can try to use BeginUpdate, EndUpdate methods:
var
  n1, n2, n3: TUniTreeNode;
begin
  nl1.BeginUpdate;
  n1 := nl1.Items.Add(nil, '11111');
  n2 := nl1.Items.Add(nil, '22222');
  n3 := nl1.Items.Add(nil, '33333');

  nl1.Items.Add(n1, 'aaaa');
  nl1.Items.Add(n2, 'bbbb');
  nl1.Items.Add(n3, 'cccc');
  nl1.EndUpdate;
end;

 

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...