|
-
Apr 20th, 2016, 02:20 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Fastest way to dump data from an array(#,#) into a datagridview or datatable
Hi
just trying to find the fastest way to put a 2 dimensional array into a datatable or datagridview, the fast possible method is what i want.
What i have setup is a class to store a cache (which comes from a query) this cache is going to be used for sorting, filtering etc, the cache is built in the following way.
ADO.NET > Adapter > DataSet > Array (DataSet to Arrays takes 20ms for 4000 rows)
now i currently setup the class to extract the table into a 2D Array and the headers into a 1D Array, just because the DataSet and DataGridView also keep them separated.
now what i want is to do it backwards
Array > DataSet OR Array > DataGridView (i want it to be around 20ms too)
currently i tried putting the array into the DataGridView but its taking 700ms....
Code:
Private Sub PopulateDataGrid_FromCache(DataGrid As DataGridView, Data As Array, Headers As Array)
Dim ColCount As Integer
Dim RowCount As Integer
Dim Row As Long
Dim Col As Integer
Dim DRow() As String
RowCount = UBound(Data, 1)
ColCount = UBound(Data, 2)
With DataGrid
'.Columns.Clear()
For Col = 0 To ColCount
.Columns.Add(columnName:="Column_" & Col, headerText:=Headers(Col))
Next
ReDim DRow(ColCount)
For Row = 0 To RowCount
For Col = 0 To ColCount
DRow(Col) = Data(Row, Col)
Next
.Rows.Add(DRow)
Next
End With
End Sub
I though it was possible to do this by columns instead of rows which in theory should be faster since there is only 9 columns, looping the array happens in milliseconds so all this extra time must be caused by accessing and adding rows to the object so adding columns should be faster if that is possible.
I also saw another method where i can build an array with a structure that can be used directly as a datasource, but how can you define a structure at runtime? is that possible......... maybe a hackjob for this is to define a structure with the max amount of columns that would be needed and delete the excess.......that may work (im using this class on multiple tables....well i will be when its working fast enough)
any ideas?
ADDITIONAL: Its no problem to change the 2D Array into an Array of 1D Arrays or to even convert it into a list when i have my results if that would be better, just as long as the process from Cache to DataGridView is less than 100ms im good with that.
Last edited by GBeats; Apr 20th, 2016 at 02:27 AM.
Yes!!!
Working from home is so much better than working in an office...
Nothing can beat the combined stress of getting your work done on time whilst
1. one toddler keeps pressing your AVR's power button
2. one baby keeps crying for milk
3. one child keeps running in and out of the house screaming and shouting
4. one wife keeps nagging you to stop playing on the pc and do some real work.. house chores
5. working at 1 O'clock in the morning because nobody is awake at that time
6. being grossly underpaid for all your hard work

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|