Destabilizator Destabilizator - 7 months ago 26
Vb.net Question

VB.NET Get everything from DataGridView

Is there a method to get all non-empty data currently in DataGridView, other than iterating through row/columns indexes? "Get" as in pump it all in array/vector or most conveniently matrix.
I'd like to do this as quickly as possible and don't care about the order of items, would Parallel.ForEach be enough?

Answer

I have figured it out, the magic is in Casting :) (DataGridView is name of my object, not the type)

Parallel.ForEach(DataGridView.Rows.Cast(Of DataGridViewRow), _
        Sub(currentRow)
            Parallel.ForEach(currentRow.Cells.Cast(Of DataGridViewCell), _
                   Sub(currentCell)
                       // do stuff
                   End Sub)
        End Sub)