When a user has many thousands of items selected in a DataGridView (we're talking hundreds of thousands or even millions) I have presently a loop but it takes way too long so remembering I have some nifty code that performed an export of selected rows to a CSV of hundreds of thousands/millions of rows in just a few seconds, I lifted out the linq/lambada code.
Slightly modifying it for my needs, I seem to be unable to get the following code working:
Dim SelectedList As New List(Of Long)
SelectedList = From row As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)()
Select Convert.ToInt64(row.Cells("ID").Value)
Getting an
Unable to cast object of type 'WhereSelectEnumerableIterator`2[System.Windows.Forms.DataGridViewRow,System.Int64]' to type 'System.Collections.Generic.List`1[System.Int64]'."
- my guess is that it doesnt like managing what I am trying to and/or converting it to Int64 is not the thing it likes, even though the item is a Long - tried int32 and I get the same error, but relating to int32. The reason why I have chosen int64 is because of the ID value records may fall out of the int32 bracket due to huge amounts of records (in their tens of millions and climbing).
I think Im very close and its only the conversion or Cast/DirectCast that would need modifying but I am stumped, or maybe is that "stupid".
Thanking you in advance for any help :)
What I have tried:
Googling "fastest way to get selected cells into a list" did not return what I wanted and neither did "vb.net datagridview using lambada to get the selected cells into a list"