MATLAB GUI程序设计中ListBox控件在运行期间消失的原因及解决方法

时间:2021-04-29 21:16:20

在运行期间,ListBox控件突然消失,同时给出如下错误提示:

Warning: single-selection listbox control requires that Value be an integer within String range
Control will not be rendered until all of its parameter values are valid

此错误经常出现在清空List之后。原因在于,List的Value属性指示当前选中的列表项序号,如果超出范围则会报错。

清空List列表项之后,Value并没有相应的清空,仍保持原来的数值,导致超出范围。

解决方法:在每次清空列表项之前,将Value置为1.