CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2000
    Location
    In a flat, Wimbledon, UK
    Posts
    251

    DataTable columns

    Is there a way, which I'm sure there is, whereby I can create the number of columns of a DataTable at runtime? I have an ArrayList with the columns that I wish to have, but the size of the ArrayList is only known at runtime.

    Btw, thanx to andy_tacker and bfarley for their help on the resizing issues. The Anchor technique worked a treat. Got some getting used to.

    Best regards

    John
    Ask a question and you're a fool for three minutes;
    do not ask a question and you're a fool for the rest of your life.
    - Chinese Proverb

  2. #2
    Join Date
    Mar 2004
    Posts
    45
    Try something like this (where list is your ArrayList):

    DataTable dt = new DataTable();

    for(int i = 0; i < list.Count; i++) {
    dt.Columns.Add("" + i);
    }


    (""+ i) is an example for your column name. Here it is the index of the data in the arraylist.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured