title: Check checkboxes in DataGridView programmatically
body: <p>I have seen a few posts similar to this issue, but I haven't come up with my answer so, I thought I would float it again to see what comes up... </p>
  
  <p>I am using ExcelDNA to integrate an API with Excel using C#.NET. I have a DataGridView, and I would like to check items that already exist on a list. </p>
  
  <p>The following code works when tied to a button-click event, but NOT when the code is called in a method. </p>
  
  <pre><code>private void SelectAllItems()
  {
      foreach (DataGridViewRow row in itemsBySupplier.Rows)
      {
          DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)row.Cells["selectItem"];
          check.Value = check.TrueValue;
      }
  }
  </code></pre>
  
  <p>I am running into the same issue elsewhere, too: </p>
  
  <pre><code>foreach (DataGridViewRow row in itemsBySupplier.Rows)
  {
      DataGridViewCheckBoxCell check = (DataGridViewCheckBoxCell)row.Cells["selectItem"];
  
      string hid = row.Cells["Hid"].Value.ToString();
      if (Ws.ToCreate[_supplier].Count(i =&gt; i.Hid == hid) &gt; 0)
      {
          check.Value = check.TrueValue;
      }
  }
  </code></pre>
  
  <p>I've been researching this for a few hours, coming up completely empty. Any help would be greatly appreciated. </p>