question

Laura Vasquez avatar image
2 Likes"
Laura Vasquez asked Matthew Gillespie edited

how to link a listbox to a dashboard button?

FlexSim 7.7.4
dashboardsmodel input
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Matthew Gillespie avatar image
1 Like"
Matthew Gillespie answered Matthew Gillespie edited

First, you need to set an ID on the listbox for easy reference. Click on the listbox and you'll see the ID field in Quick Properties. For the next steps I'm going to assume you entered myListBox as the ID.

Second, you'll need to add some custom code to the On Press trigger of your button. Click on your button and find the On Press trigger field. Click the properties button and choose Code Snippet from the list (or just open the code editor). Enter your code, here is some example code that will populate the listbox with the list of objects in your model:

  1. treenode list = getdashboardcontrol("myListBox");
  2. clearcontents(items(list));
  3.  
  4. for(int i = 2; i <= content(model()); i++) {
  5. treenode listItem = nodeinsertinto(items(list));
  6. setname(listItem, getname(rank(model(), i)));
  7. }
  8.  
  9. listboxrefresh(list);

We're using getdashboardcontrol("myListBox") to get a reference to your listbox. The contents displayed by the listbox are represented by nodes on the listbox's items node. So first we clear the contents of that node. Then we loop through all the objects in the model and add a new subnode to the listbox's items node and give it the name of the object it's representing. Finally, to refresh the listbox and show the new values we call listboxrefresh on the listbox.

Third, you'll need to clear the Edit Mode check box in quick properties either for the whole dashboard or just for the button.

· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.