MATLAB Answers

0

(App Designer) ListBox Callback - does my value need to change to get a callback?

Asked by Hannah Gillespie on 21 Jun 2019
Latest activity Commented on by Guillaume
on 26 Jun 2019
Hi all,
I have a ValueChangedFnc (Value changed function) for my listbox that correctly responds when I select a different item in my list. I would like the same callback to occur when I click the currently selected item (the value does not change but I would like to repeat the callback).
Is there any other way to add callbacks to the listbox? or do I need to de-select the current item in order to repeat it?
Thanks!
HG

  2 Comments

Hannah - for the ValueChangedFnc callback, I suspect that the value (selected item) would need to change in order for the callback to fire. Why would you like to re-select the the already selected item? What would be the purpose of doing that?
Hi Geoff,
I basically have two listboxes, one contains x axis information and one contains y axis information. When I select any item in the y axis information box, my gui plots it with respect to whatever is selected in the x axis information box. Now I want to be able to compare the plots with other conditions, so I want to plot the same y axis information with different data sets uploaded. However, my y axis selection is not deselected and I cannot plot the same y data again without first selecting something different. Thanks!

Sign in to comment.

1 Answer

Answer by Guillaume
on 24 Jun 2019

It sounds like you need to change your design slightly. At the moment, it sounds like you're only plotting when y changes but actually you also want to plot when some other information changes. So, extract the plotting code in its own function and call that plotting function from the callback of each relevant control (x, y, etc.)

  4 Comments

Show 1 older comment
In this instance, I wouldn't say that the App designer has reduced functionality, I'd say it has a much saner design.
As the name indicates, ValueChangedFnc only fires when the values changes. You could possibly detect "when the user clicks a list box item" by catching the WindowButtonDown event of the app but your app would only work properly for mouse users. Keyboard users would be left out.
In any case, that wouldn't be very good design. As I said, if you want something to change in response to any of several things changing, the best course of action is to call that change function from the event handler of each of these things.
If you really need to you can also have a Refresh button.
True, App Designer is much more user friendly!
The WindowButtonDown event actually sounds like exactly what I would need. How do I incorporate that callback in App Designer?
Again, I wouldn't recommend using any ***Button*** event as you leave keyboard users (like me) unable to use your GUI. ***Change events can be triggered by keyboard or mouse interactions and are thus more useful.
Furthermore, the WindowButtonDown event of a figure might get intercepted by controls in the figure or might not be triggered on some controls. See the documentation.
As to how incorporate it, the same way you create any other App designer callback. The simplest way is to select the UIFigure in the list of components, go to callbacks and let matlab create the callback function for you.

Sign in to comment.