-2

Here is what I'm currently using. It works fine, but takes several seconds to complete. Is there a faster way? I've tried creating a list of DataColumn and using table.columns.addRange(list.toArray) with no improvement. I just need the columns to be numbered from 0 to 67.

If appTable.Columns.Count = 0 Then
    'adds columns 0 to 67 to table                
    For x = 0 To 67 Step 1
        appTable.Columns.Add(x, GetType(String))
    Next
End If
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
Matt
  • 11
  • 1
  • 1
  • Start with putting `Option Strict On` at the top of your code file - that code will not even compile. It only takes 1.2 secs for me - not sure what your expectations are. Please read [ask] and take the [tour] – Ňɏssa Pøngjǣrdenlarp Feb 06 '18 at 23:00
  • Adding columns to an in memory DataTable shouldn't be a huge bottleneck by itself. Does your Table have any rows? Is it bound to some UI that might be doing updating? Does is have a linked DataSet with Relations that need checking? – user6144226 Feb 06 '18 at 23:00
  • using x.ToString I get 6 milliseconds – Mary Feb 07 '18 at 00:32

1 Answers1

0

I feel like an idiot. user6144226 answered my question. I was using the DataTable as the DataSource for a DataGridView prior to adding the columns. This is what caused the bottleneck.

I added the columns to the DataTable prior to setting it as the DataSource and everything runs much more quickly. Thank you for your responses.

Matt
  • 11
  • 1
  • 1