Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
add new string to listbox

Subject: add new string to listbox

From: zheng chew

Date: 26 Mar, 2011 01:21:04

Message: 1 of 3

Hi

How can I add new strings into a listbox?

By using \n doesn't seem to do the job.
I tried:

initial_name=get(handles.listbox,'String')
new_name = sprintf('%s\n%s',initial_name,new_line) % assume there is a string store in variable new_line
set(handles.listbox,'String',new_name) gives the new_line and initial_line on the same line.

Thanks
Zheng

Subject: add new string to listbox

From: Think blue, count two.

Date: 26 Mar, 2011 03:58:11

Message: 2 of 3

On 25/03/11 8:21 PM, zheng chew wrote:

> How can I add new strings into a listbox?
> By using \n doesn't seem to do the job.
> I tried:
>
> initial_name=get(handles.listbox,'String')
> new_name = sprintf('%s\n%s',initial_name,new_line) % assume there is a
> string store in variable new_line
> set(handles.listbox,'String',new_name) gives the new_line and
> initial_line on the same line.

initial_name=cellstr(get(handles.listbox,'String'));
new_name = [initial_name;{new_line}];
set(handles.listbox,'String',new_name)

Subject: add new string to listbox

From: Punk Trader

Date: 17 Nov, 2011 21:20:29

Message: 3 of 3

"Think blue, count two." <roberson@hushmail.com> wrote in message <nvdjp.1160$4S1.799@newsfe21.iad>...
> On 25/03/11 8:21 PM, zheng chew wrote:
>
> > How can I add new strings into a listbox?
> > By using \n doesn't seem to do the job.
> > I tried:
> >
> > initial_name=get(handles.listbox,'String')
> > new_name = sprintf('%s\n%s',initial_name,new_line) % assume there is a
> > string store in variable new_line
> > set(handles.listbox,'String',new_name) gives the new_line and
> > initial_line on the same line.
>
> initial_name=cellstr(get(handles.listbox,'String'));
> new_name = [initial_name;{new_line}];
> set(handles.listbox,'String',new_name)

Hi,

Just create a cell and set by handles.

for i=1:length(list)
handles.names(i)=list(i) % fill handles struct with values that you want like to input in
end
set(handles.Listbox1,'String',handles.names)

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us