How can I add 'delete' button to listdlg?

4 次查看(过去 30 天)
Hello all! Well I have such code
% code
s.a=2;
s.b=3;
s.c=4;
s.d=5;
str=fieldnames(s);
[s,v] = listdlg('PromptString','Select a file:',...
'SelectionMode','single',...
'ListString',str)
That gives me a figure where are only 'ok' and 'cancel' buttons as default, but now I want to have delete button with which I will be able delete selected variable from s structure. Any ideas would be a great job for me, Thanks in advance.

回答(1 个)

Stephen23
Stephen23 2015-2-16
编辑:Stephen23 2015-2-16
The standard listdlg does not support adding other buttons (or features), but one of the neat things about MATLAB is you can often adapt MATLAB's own code for your own purposes: you could rewrite the listdlg function to include another button, and make it do whatever you want it to do. Start by opening listdlg:
open listdlg
and then save a copy in your working directory, changing both the function and file names.
Then search for bushbutton: you will find three instances of uicontrol that are used to define the two standard and open optional button: you can easily change the code to add new buttons and features. You will need to read about uicontrol and understand how callback functions work. You will need to consider how to keep track of the cell of strings listString and change this using the delete button, and also how to refresh the listbox uicontrol when this happens.
  2 个评论
Giorgi
Giorgi 2015-2-16
Well I am beginner here so that's too hard for me :(, is there any other way? because the idea is that I have mat file and one button and when I click this button it have to open figure like listbox, where is written all the names of the existing variables those are in this mat file, and when you select one of them you should get the values of selected variable, and also it should have delete button with which you will be able to delete selected variable. Is everything clear?
Stephen23
Stephen23 2015-2-16
编辑:Stephen23 2015-2-16
Consider doing this instead using two list boxes: one for selecting, one for deleting. This would mean you could use the standard listdlg and keep these two functionalities separate. This would be simpler code than rewriting the listdlg function.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by