cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

Translate the entire conversation x

Advanced Controls - List Box - selection not preserved

Andy_C
12-Amethyst

Advanced Controls - List Box - selection not preserved

I noticed an issue with MCP11 vs 10 regarding Advanced Controls List Boxes where the selection is not preserved when a file is saved/closed/reopened. Anyone else seeing this issue?

Without selection preservation, List Boxes are basically useless. I haven't yet checked if the other types (checkboxes, radio buttons, etc.) maintain selection.

list box code (this worked in MCP10 w/o issue):

// TODO: Add your initialization code here
ListBox.ResetContent();
var list1 = Inputs[0].Value;
var list2 = Inputs[1].Value;

// Add Strings here as needed
for (var i = 0; i < list2.length; i++) {
ListBox.AddString(list2[i]);
}

function ListBoxEvent_Start(Inputs, Outputs) {
// TODO: Add your code here
};

function ListBoxEvent_Exec(Inputs, Outputs) {
Outputs[0].Value = list1[ListBox.CurSel()];
};

function ListBoxEvent_Stop(Inputs, Outputs) {
// TODO: Add your code here
};

function ListBox_SelChanged(Inputs, Outputs) {
// TODO: Add your code here
};

function ListBox_DblClick(Inputs, Outputs) {
// TODO: Add your code here
};

Andy_C_0-1753245409415.png

Andy_C_2-1753245600237.png

 

 

10 REPLIES 10

So I'm comparing two test List Box examples (the JScript example in Help https://support.ptc.com/help/mathcad/r11.0/en/index.html#page/PTC_Mathcad_Help/example_listbox.html# ).

 

Mathcad Prime 10.0.1.0 retains the selection after saving and closing when you remove the ListBox.CurSel(0); from the example, which you did, wisely. That's all. You may have whatever option selected you want. This matches up with your experience.

 

Mathcad Prime 11.0.0.0 will only retain the selection after saving and closing when you both do that and you disable the "Run Advanced Control script on worksheet open"  option in PTC Mathcad Options. Do you have that option disabled?

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Andy_C
12-Amethyst
(To:DJNewman)

Hi @DJNewman , 
Thanks for the reply.

So, I've been testing by saving and closing repeatedly as I've been trying to update my MCP10 scripts to get this to work, but haven't had any luck. Also, I first realized this issue when I opened a MCP10 file (w/ the working script) in 11 and all my list box selections were reset. So, the 10 file had already been saved and closed. And, yes, the "Run Advanced Control script on worksheet open" option has been disabled as a default (I've never used that one). What else do you think I am missing?

Andy_C_0-1753297055091.png

 

Without your worksheet (not just the script in the boxes but how the inputs are made too), I can't really take time to test things, but since I know you have access to opening a PTC Tech Support case, you should do that and send them your worksheet and they can help you out. And if it's a bug of some sort, then they'd be able to identify that as something to be fixed in the next version.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Andy_C
12-Amethyst
(To:DJNewman)

Thanks, @DJNewman . I have created a Support case. I will follow up with the results.

Andy_C
12-Amethyst
(To:Andy_C)

Short update:
PTC moved my case to the Software Performance Report (SPR) dev team on 7/29/25 so I am waiting to hear back from them. No updates as of 8/5.  I'll be sure to follow up when I know more.

DhirajPatil
15-Moonstone
(To:Andy_C)

Hi @Andy_C
The issue reported in the SPR has been fixed in the latest release of the Mathcad Prime date code 11.0.1.0. 
Regards, 

Dhiraj 

I can verify this difference in behavior.  However, initially my own controls were working just fine in Prime 11.

 

I started a clean sheet and dropped in a set of Radio Buttons and a List Box and, using the default Jscript code, modified the selection, saved the file, closed the file, re-opened the file, and my selections were preserved.  No problem in 10 or 11, with the caveat that the run script options on startup and recalculation must be turned off as DJ mentioned.

 

The default Jscript, however, creates a static set of Listbox entries (as do mine).  I modified the script to populate the listbox dynamically with an input array of text items, like you did in your script.   Bingo.  The previously selected item gets erased when the worksheet is re-opened.  Thinking on this, if the list is getting populated by an input vector of choices, the script has no idea what they are or how many there are, and should have to re-run (even though the run script options are unchecked) to repopulate the list.  I think this makes sense.  Think about if the input selection was index 10 and a new set of choices was provided (maybe read from a file that changed outside of Mathcad) with only 5 items. Several things would go wrong here.

 

I'm not sure why Prime 10 didn't behave the same way, and possibly someone fixed the bad behavior in Prime 11 as it caused some other side effect.

 

Anyway, it looks like if you don't pass the list in and use a static set of List choices, the script won't re-run and reset.  I'm still experimenting on how to keep that from happening through the VB Script, but so far the selection gets lost on re-open.

So, since this thread was made, I've had a few talks with the Mathcad Team, and they've actually been investigating this.

 

There were some changes R&D made to Advanced Controls in terms of event handling that were not documented anywhere, despite them changing how your worksheets work from one version to another. One of the things that we (Mathcad's application engineers) want to do in the coming months is document those secret changes (in a Mathcad blog) and supply some best practices on what to expect when you put certain scripts in different events, for each control.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Andy_C
12-Amethyst
(To:DJNewman)

Thanks for the update, @DJNewman

 

A blog with a best practices explainer would be helpful. Are you able to expand on this topic now?

 

Overall, I am curious about List Box selection preservation because it seems that if this feature is gone, the List Box component is practically of no use. Afterall, it is just a fancy variable definition (:=). Can you imagine if all other variable definition values cleared each time one re-opened a file! 😄

I can't expand on it now since it's not fully fleshed out yet, but I'll see if I can expand on it to you before the blog is published.

I manage the Creo and PTC Mathcad YouTube channels for PTC, as well as all PTC Mathcad marketing in general.
Announcements

Top Tags