Al Lelopath Al Lelopath - 1 year ago 221 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.

Answer Source

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 )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download