title: DataGridView has no columns
body: <p>This is c# windows forms.</p>
  
  <p>I have a data grid view that is supposed to display two columns, file names, and modified date.  The way that I'm doing this is through a task.  I also have a class that hold only the file and path name, bindingsource, and data grid view.  This task runs a method where the class is passed.  Once the task is complete the class should have a grid view that I can then set to a gridview back on the form.</p>
  
  <p>The class looks like this:</p>
  
  <pre><code>class GetLogFilesParameters
  {
      public string FileNameandPath;
      public BindingSource BindingSource;
      public DataGridView GridView;
  
      public GetLogFilesParameters(string _fileNameAndPath)
      {
          FileNameandPath = _fileNameAndPath;
          BindingSource = new BindingSource();
          GridView = new DataGridView();
          GridView.DataSource = BindingSource;
      }
  }
  </code></pre>
  
  <p>The method my task is calling look like this:</p>
  
  <pre><code>private static void GetLogFilesTest(GetLogFilesParameters FormFields)
      {
          Cursor.Current = Cursors.WaitCursor;
  
          try
          {
              //Setup data table
              DataTable FileList = new DataTable();
              FileList.Clear();
              DataColumn FileNameColumn = new DataColumn();
              FileNameColumn.ColumnName = "FileName";
              FileNameColumn.DataType = System.Type.GetType("System.String");
  
              DataColumn DateColumn = new DataColumn();
              DateColumn.ColumnName = "ModifiedDate";
              DateColumn.DataType = System.Type.GetType("System.DateTime");
  
              FileList.Columns.Add(FileNameColumn);
              FileList.Columns.Add(DateColumn);
  
              //Get a list of files in a directory
              string[] files = Directory.GetFiles(FormFields.FileNameandPath, "*.log");
  
              //Loop through the files and fill the data table with a row for each
              foreach (string file in files)
              {
                  FileInfo FileInformation = new FileInfo(file);
                  DataRow row = FileList.NewRow();
                  row["FileName"] = FileInformation.Name;
                  row["ModifiedDate"] = FileInformation.LastWriteTime;
                  FileList.Rows.Add(row);
              }
  
              //FormFields.GridView.Columns.Add("FileName", "File Name");
              //FormFields.GridView.Columns.Add("ModifiedDate", "Modified Date");
              FormFields.GridView.AutoGenerateColumns = true;
  
              //Setup the binding source
              FormFields.BindingSource.DataSource = FileList;
              FormFields.BindingSource.Sort = "ModifiedDate DESC";
  
              FormFields.GridView.Columns[0].Width = (FormFields.GridView.Width / 10) * 6;
              FormFields.GridView.Columns[1].Width = (FormFields.GridView.Width / 10) * 4;
          }
          catch (Exception ex)
          {
              string ErrorText = "Error trying to get the list of log files." + Environment.NewLine + Environment.NewLine;
              ExceptionLogger.LogIt(ErrorText, "Exception");
              MessageBox.Show(ErrorText + ex.ToString());
          }
          finally
          {
              Cursor.Current = Cursors.Default;
          }
      }
  </code></pre>
  
  <p>My task looks like this:</p>
  
  <pre><code>GetLogFilesParameters GetLogFilesParameters = new GetLogFilesParameters(EpicorSenderPath);
              Task tGetFiles1 = new Task(() =&gt; GetLogFilesTest(GetLogFilesParameters));
              tGetFiles1.Start();
              tGetFiles1.ContinueWith((antecedent) =&gt;
                  {
                      gvEpicorSenderFiles = GetLogFilesParameters.GridView;
                  }, TaskScheduler.FromCurrentSynchronizationContext());
  </code></pre>
  
  <p>The error I get is System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.  It happens in the method on this line:</p>
  
  <pre><code>FormFields.GridView.Columns[0].Width = (FormFields.GridView.Width / 10) * 6;
  </code></pre>
  
  <p>This is happening because the gridview doesn't have any columns according to the debug.  Also, when it DOES have rows and data.  I don't know what is wrong.</p>