Click here to Skip to main content
15,897,273 members

How do I convert an array to a list of double

Member 12561559 asked:

Open original thread
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"
Tags: Visual Basic, DataGridView

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900