Vb.net – How to convert a List(Of T) to an ObservableCollection(Of T) in VB.NET


Is there a way to do this without iterating through the List and adding the items to the ObservableCollection?

Best Solution

No, there is no way to directly convert the list to an observable collection. You must add each item to the collection. However, below is a shortcut to allow the framework to enumerate the values and add them for you.

Dim list as new List(of string)
...some stuff to fill the list...
Dim observable as new ObservableCollection(of string)(list)