- https://www.mathworks.com/help/matlab/ref/matlab.ui.control.listbox.html?s_tid=srchtitle_support_results_1_listbox#mw_7c6b8324-262d-46c1-914c-a53a0137e73e
- https://www.mathworks.com/help/matlab/ref/matlab.ui.control.listbox.html?s_tid=srchtitle_support_results_1_listbox#mw_022f6842-efe7-4abd-a21c-8bdec58c06f5
GUI List box selected items shown in text button
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I have multiple lines in listbox . I want to assign names to the selected lines and display it on text button. For example if 1st line is selected then it should display 'Line 1' on text button and so on.
here is my listbox.please help.

0 Commenti
Risposte (1)
Anay
il 2 Lug 2025
Hi Tayyaba,
I understand that you want to display the number of selected line in the listbox on a button.
Each entry in the listbox has an index. Index of the current selection of the listbox can be obtained by using the “ValueIndex” property of the listbox object. This index can be used as the “line number”.
You can use the “ValueChangedFcn” callback which is triggered whenever the current selection in listbox is changed. In this callback, change the text on the button.
You can refer to the following code:
function listBoxValueChanged(event, button)
idx = event.ValueIndex;
button.Text = ['Line ' num2str(idx)];
end
fig = uifigure;
lb = uilistbox(fig,"Items",["Red","Green","Blue"]);
b = uibutton(fig);
lb.ValueChangedFcn = @(~,event) listBoxValueChanged(event, b);
You can find more information about listbox by following the below links:
0 Commenti
Vedere anche
Categorie
Scopri di più su Desktop in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!