How to reference and act on a dynamically created ListBox?<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />Hello,
I needed to build a GUI that was capable of adding and removing ListBox entries with a simple button click.
I managed to figure out how to add ListBox/button (wrapped in an HListBox) pairs dynamically using the script below, but I am not sure how to reference them for the delete button.
NewWindow("WINDOW_NAME", << Modal,
OutlineBox("OUTLINE_NAME",
test_lb = VListBox(
ButtonBox("Add",
test_lb << Append(
HListBox(
OutlineBox("TEST_INSTANCE_" || Char(Today())),
ButtonBox("Remove" //somehow remove only the current HListBox object
)
)
)
),
ButtonBox("OK")
)
)
);
Re: How to reference and act on a dynamically created ListBox?Hi, Jason.
The following example demonstrates how to use a function to self-reference the ButtonBox and then delete the parent in the Remove button:
New Window( "WINDOW_NAME",
<<MODAL></MODAL>
I hope that helps!
Wendy
Re: How to reference and act on a dynamically created ListBox?Working at this a bit longer, I figured the only way to do this was to give each box a dynamic index using Eval(Parse(EvalInsert())) commands.
There might be a better way to do it, but this seemed to work for me.
test_inst = 0;
NewWindow("WINDOW_NAME", << Modal,
OutlineBox("OUTLINE_NAME",
test_lb = VListBox(
ButtonBox("Add", test_inst += 1;
Eval(
Parse(
EvalInsert("
test_lb << Append(
test_inst_lb_^test_inst^ = HListBox(
OutlineBox(\!"TEST_INSTANCE_\!" || Char(^test_inst^)),
TextBox(Char(^test_inst^)),
test_inst_bb_^test_inst^ = ButtonBox(\!"Remove\!",
Print(<<GETPROPERTYLIST></GETPROPERTYLIST>