title: Using List content for filtering datagridview C#
body: <p>I've been struggling with this question for a few days now and I haven't found any answer yet; I created a <code>ToolStripMenu</code> array which is filled dynamically from a stored procedure:</p>
  
  <pre><code>ToolStripMenuItem[] itemsDepto = null;
  itemsDepto = new ToolStripMenuItem[data.Tables[0].Rows.Count];
  for (int i = 0; i &lt;= data.Tables[0].Rows.Count - 1; i++)
  {
       itemsDepto[i] = new ToolStripMenuItem();
       itemsDepto[i].Tag = data.Tables[0].Rows[i].ItemArray[0];
       itemsDepto[i].Text = data.Tables[0].Rows[i].ItemArray[1].ToString();
       itemsDepto[i].CheckOnClick = true;
       itemsDepto[i].Checked = true;
       itemsDepto[i].Click += DeptoFilter_Click;
       deptoList.Add(data.Tables[0].Rows[i].ItemArray[1].ToString());
  }
  tsmiDepartamento.DropDownItems.AddRange(itemsDepto);
  </code></pre>
  
  <p>And what I'm trying to achieve is use this <code>ToolStripMenu</code> as a filter control for the user, by default is Checked so when the user unchecks the menu, it should filter the rows with the content that is unchecked.</p>
  
  <p><img src="https://i.stack.imgur.com/HE0EV.png" alt=""></p>
  
  <p>In the click event I add and remove values from the list depending on the state of the menu button as you can see in the following example:</p>
  
  <pre><code>private void DeptoFilter_Click(object sender, EventArgs e)
  {
      ToolStripMenuItem temp = new ToolStripMenuItem();
      temp = (ToolStripMenuItem)sender;
      BindingSource bind = new BindingSource();
      bind.DataSource = dgvPersonalTotal.DataSource;
      if (temp.CheckState == CheckState.Checked)
      {
          deptoList.Add(sender.ToString());
      }
      else
      {
          deptoList.Remove(sender.ToString());
      }
      bind.Filter = "Departamento NOT IN (" + /*LIST*/"" + ")";
      dgvPersonalTotal.DataSource = bind;
      //foreach (string x in deptoList)
      //{
      //}
  }
  </code></pre>
  
  <p>But the big question I have is, how can I use a list to filter the Binding Source, as you can see in the code, I can't just use the list or even try use the BindingSource.Filter in the foreach, I don't know how to resolve this problem, so any idea is well appreciated.</p>