title: No row can be added to a DataGridView control that does not have columns. Columns must be added first.'
body: <p>So, I'm creating a program to check names of a client. But I get this error.
  "No row can be added to a DataGridView control that does not have columns. Columns must be added first.'"
  I'm unsure of what to do at this point, as it's all coded correctly. and I just, I don't understand why it's not working. A friend of mine is running the EXACT same code, and his build worked flawlessly.</p>
  
  <p>Here's my code.</p>
  
  <pre><code>        private void PopulateDataGrideView(string Name, string Status)
      {
          if (base.InvokeRequired)
          {
              base.BeginInvoke(new MethodInvoker(() =&gt; {
                  DataGridViewRow dataGridViewRow = new DataGridViewRow();
                  if (Status == "Yes")
                  {
                      dataGridViewRow.DefaultCellStyle.BackColor = Color.LightGreen;
                      Status = "Name Available";
                  }
                  else if (Status == "No")
                  {
                      dataGridViewRow.DefaultCellStyle.BackColor = Color.Red;
                      Status = "Not Available";
                      if (this.VisibilityBx.Checked)
                      {
                          dataGridViewRow.Visible = false;
                      }
                  }
                  dataGridViewRow.CreateCells(this.checkedNames, new object[] { Name, Status });
                  this.checkedNames.Rows.Add(dataGridViewRow);
                  if (scrollBx.Checked)
                  {
                      this.checkedNames.FirstDisplayedScrollingRowIndex = this.checkedNames.RowCount - 1;
                  }
                  this.progressBar1.Increment(1);
              }));
          }
      }
  
      private void saveAvailableNamesToolStripMenuItem_Click(object sender, EventArgs e)
      {
          List&lt;string&gt; strs = new List&lt;string&gt;();
          if (this.checkedNames.Rows.Count &gt; 0)
          {
              foreach (DataGridViewRow row in (IEnumerable)this.checkedNames.Rows)
              {
                  if (row.Cells[1].Value.Equals("Name Available"))
                  {
                      strs.Add(row.Cells[0].Value.ToString());
                  }
              }
              if (strs.Count &gt; 0)
              {
                  string currentDirectory = Environment.CurrentDirectory;
                  DateTime now = DateTime.Now;
                  File.WriteAllLines(string.Concat(currentDirectory, "\\Available Names ", now.ToString("dd-MM-yyyy HH.mm.ss tt"), ".txt"), strs);
              }
          }
      }
  
      private void saveTakenNamesToolStripMenuItem_Click(object sender, EventArgs e)
      {
          List&lt;string&gt; strs = new List&lt;string&gt;();
          if (this.checkedNames.Rows.Count &gt; 0)
          {
              foreach (DataGridViewRow row in (IEnumerable)this.checkedNames.Rows)
              {
                  if (row.Cells[1].Value.Equals("Not Available"))
                  {
                      strs.Add(row.Cells[0].Value.ToString());
                  }
              }
              if (strs.Count &gt; 0)
              {
                  string currentDirectory = Environment.CurrentDirectory;
                  DateTime now = DateTime.Now;
                  File.WriteAllLines(string.Concat(currentDirectory, "\\Taken Names ", now.ToString("dd-MM-yyyy HH.mm.ss tt"), ".txt"), strs);
              }
          }
      }
  
      private void scrollBx_CheckedChanged(object sender, EventArgs e)
      {
          if (this.checkedNames.RowCount &gt; 0)
          {
              if (this.scrollBx.Checked)
              {
                  this.checkedNames.FirstDisplayedScrollingRowIndex = this.checkedNames.RowCount - 1;
              }
              else if (!this.scrollBx.Checked)
              {
                  this.checkedNames.FirstDisplayedScrollingRowIndex = 0;
              }
          }
      }
  
      private void VisibilityBx_CheckedChanged(object sender, EventArgs e)
      {
          if (this.checkedNames.Rows.Count &gt; 0)
          {
              foreach (DataGridViewRow row in (IEnumerable)this.checkedNames.Rows)
              {
                  if (!this.VisibilityBx.Checked)
                  {
                      if (!row.Visible)
                      {
                          row.Visible = true;
                      }
                  }
                  else if (this.VisibilityBx.Checked)
                  {
                      if ((string)row.Cells[1].Value == "Not Available")
                      {
                          row.Visible = false;
                      }
                  }
              }
          }
      }
  
      private void Form1_Load(object sender, EventArgs e)
      {
  
      }
  
      private void CheckedNames_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
  
      }
  }
  </code></pre>
  
  <p>}</p>