GUI List box selected items shown in text button

2 vues (au cours des 30 derniers jours)
Tayyaba Abro
Tayyaba Abro le 18 Fév 2021
Réponse apportée : Anay le 2 Juil 2025
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.

Réponses (1)

Anay
Anay le 2 Juil 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:

Catégories

En savoir plus sur Desktop dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by