Rosen Karadinev
Rosen Karadinev

Reputation: 205

C# ListView to List<string>

I have a ListView with string items, and i am trying to get these items and store them in List container.

I need the reverse operation of this:

List<string> myList = new List<string> { "Item1", "item2", "item3"}; 
resultsList.ItemsSource = myList;

So my Question is How to Parse ListView with Items to List?

Upvotes: 0

Views: 493

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460108

I think you can cast and use ToList to create a list:

myList = resultsList.ItemsSource.Cast<string>().ToList();

Upvotes: 2

Kamil Budziewski
Kamil Budziewski

Reputation: 23087

You need to cast it to IEnumerable<string>

List<string> myList = ((IEnumerable<string>)resultsList.ItemsSource).ToList();

Upvotes: 3

Related Questions