Al Lelopath Al Lelopath - 8 months ago 121 Question

How to convert a DataGridView to List

I've tried the following:

Compile error (on last As)

Dim myList As New List(Of Object)
myList = dataGridView.DataSource As List<Object>

Throws Unable to cast object of type System.Windows.Forms.BindingSource:

myList = dataGridView.DataSource

DataSource is a
where T is a custom class.


This is how I did it:

Dim MyList As New List(Of Object) ' Of MyClass?
For Each myClass As MyClass In dataGridView.DataSource
    MyList.Add(myClass )