title: C# adding to list object from checkbox
body: <p>I am sure that someone has asked this before, but I am not searching for the right terms or something because I just can't seem to find what I am looking for.</p>
  
  <p>I have a class Packages:</p>
  
  <pre><code>class Packages
  {
      string PackageID {get; set;}
      string PackageName { get; set; }
  }
  </code></pre>
  
  <p>I have a list of packages in my context.</p>
  
  <pre><code>public class TransferJobContext
  {
      public string ImportFile;
      public string WorkSheetName;
      public DataSet TransferData;
      public List&lt;Packages&gt; Packages = new List&lt;Packages&gt;();
  }
  </code></pre>
  
  <p>I have a checkedListBox on my form that is bound to a datasource.  Here is the section of code where I get the values into the checkedListBox</p>
  
  <pre><code>using (var connection = my_DB.GetConnection())
  {
      try
      {
          connection.Open();
          SqlDataReader rdr = null;
          dt = new DataTable();
          string CommandText = "SELECT ID, Name FROM TABLENAME WHERE UPPER(Import_File_Source) LIKE '%abc%' and STATUS = 1";
  
          SqlCommand cmd = new System.Data.SqlClient.SqlCommand(CommandText, connection);
  
          rdr = cmd.ExecuteReader();
          dt.Load(rdr);
          cbPackages.DataSource = dt;
          cbPackages.ValueMember = "ID";
          cbPackages.DisplayMember = "Name";
  
      }
      catch (Exception E)
      {
          MessageBox.Show(E.Message.ToString());
      }
      connection.Close();
  }
  </code></pre>
  
  <p>How do I add a new Package to the list when an item is checked using the value member and displaymember of the selected items?</p>
  
  <p><strong>Edit:</strong>  Ok maybe I am going about this completely wrong.  Instead of telling you what I have done, I'll tell you what I would like to happen.</p>
  
  <p>I am presenting my user with a checkedlistbox that has a list of names with check boxes next to them.  They can select more than one.  This results in me having one or more ID(s) to use in my query and name(s) to use as a description.  I need to pass around with my context the one or many id/name combinations of my "Package".</p>
  
  <p>What is the best what to capture the ID/Name combination of the selections the user made and pass them into my context?</p>