Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a ListBoxItem in a ListBox in C#?

Tags:

I know that:

String test = "test"; ListBox.Items.Add(test); 

or

String test = "test"; int index = 1; ListBox.Items.Insert(index, String); 

adds the String in a ListBox, but I want to insert ListBoxItem, how to? previously I learn that

var contentToString = (String)ListBoxItem.Content; 

simply converts ListBoxItem to String, but I couldn't do the opposite to convert String to ListBoxItem

like image 412
Hendra Anggrian Avatar asked Nov 07 '12 10:11

Hendra Anggrian


1 Answers

Try this:

ListBoxItem itm = new ListBoxItem(); itm.Content = "some text";  listbox.Items.Add(itm); 

listbox is name for ListBox.

like image 119
Danilo Vulović Avatar answered Oct 01 '22 18:10

Danilo Vulović