list box string isn't updated after changes

4 Ansichten (letzte 30 Tage)
evgeny shumsky
evgeny shumsky am 16 Sep. 2019
Bearbeitet: evgeny shumsky am 18 Sep. 2019
Hi all, i have created gui with guide.
I have 4 push buttons: add, remove, up, down
1.JPG
the problem is with "add" button. the list box excepts the string from "editbox" and add it between the selected value of the list box
2.JPG
but when i try to add another string it replaces the existing on with the new one.
how can i keep the added string to the list and adding another one without removing the previous?
this is the push button callback
function add_Callback(hObject, eventdata, handles)
editbox = get(handles.edit,{'string'}); %need {} because editbox is a char
Lstring = get(handles.listbox,'string');
Lvalue = get(handles.listbox,'value');
% update the string in the selected place with the editbox data
%Lstring(Lvalue)=[editbox]
Value=Lvalue+1;
low=1:Lvalue;
low1=num2str(low');
high=Value:50;
high1=num2str(high');
new = [low1 editbox high1];
set(handles.listbox,'string',new,'value',Value);

Akzeptierte Antwort

Kevin Phung
Kevin Phung am 16 Sep. 2019
it gets removed because of the way you are building your string.
low=1:Lvalue;
low1=num2str(low');
high=Value:50;
high1=num2str(high');
new = [low1 editbox high1];
you are always setting the strings before and after your selection to be 1:Lvalue and value:50.
I would suggest doing this:
Add editbox string directly below the selection.
function add_Callback(hObject, eventdata, handles)
editbox = get(handles.edit,{'string'}); %need {} because editbox is a char
Lstring = get(handles.listbox,'string');
Lvalue = get(handles.listbox,'value');
% update the string in the selected place with the editbox data
%Lstring(Lvalue)=[editbox]
new = [Lstring(1:Lvalue) editbox Lstring(Lvalue)];
Value = Lvalue+1
set(handles.listbox,'string',new,'value',Value);
let me know if this works for you
  1 Kommentar
evgeny shumsky
evgeny shumsky am 18 Sep. 2019
Bearbeitet: evgeny shumsky am 18 Sep. 2019
it wan't working
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
Error in ==> GUI_final>add_Callback at 103
new = [Lstring(1:Lvalue) editbox Lstring(Lvalue)];
so i changed it a little bit and now every thing works
Value=Lvalue+1;
new = [Lstring(1:Lvalue); editbox; Lstring(Value:end)];
thank you, you have helped me alot

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Produkte


Version

R2008b

Community Treasure Hunt

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

Start Hunting!

Translated by