Subscribe Bookmark RSS Feed

How to reference and act on a dynamically created ListBox?

jason_paquette

Community Trekker

Joined:

Jan 26, 2015

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")

  )

)

);

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

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,

  Outline Box( "OUTLINE_NAME",

       test_lb = V List Box(

            Button Box( "Add",

                 test_lb << Append(

                      H List Box(

                           Outline Box( "TEST_INSTANCE_" || Char( Today() ) ),

                           Button Box( "Remove", <<Set Function( Function( {this}, (this << Parent) << Delete ) ) )

                      )

                 )

            ),

            Button Box( "OK" )

       )

  )

);

I hope that helps!

Wendy

Wendy
2 REPLIES
jason_paquette

Community Trekker

Joined:

Jan 26, 2015

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);

          test_inst_lb_^test_inst^ << Delete;

         )  

        )       

       )"

      )

     )

    )   

   ),

   ButtonBox("OK")

  )

)

);

Solution

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,

  Outline Box( "OUTLINE_NAME",

       test_lb = V List Box(

            Button Box( "Add",

                 test_lb << Append(

                      H List Box(

                           Outline Box( "TEST_INSTANCE_" || Char( Today() ) ),

                           Button Box( "Remove", <<Set Function( Function( {this}, (this << Parent) << Delete ) ) )

                      )

                 )

            ),

            Button Box( "OK" )

       )

  )

);

I hope that helps!

Wendy

Wendy