title: Create controls during runtime and access their values
body: <p>I'm trying to create CheckedListBox's at runtime from the data that is in a database table.</p>
  
  <p>Data in the table for example</p>
  
  <pre><code>Kern
  Formax
  Buhrs
  </code></pre>
  
  <p>for each row in the table I want the code to create a new CheckedListBox with a name of the row.</p>
  
  <p>After the creating of the CheckedListBox I want to populate it from another table containing other data.</p>
  
  <p>As soon as the client is done with the data selection in the CheckedListBox's I want to read all the checked values in the CheckedListBox's and save it into an array.</p>
  
  <p>My trouble comes with creating the CheckedListBox's and accessing the data as soon as the client clicks done.</p>
  
  <p>I'm very new to creating controls at runtime.</p>
  
  <p>Thanks in advance:)</p>
  
  <p>I have solved this by creating an array of checkedlistboxs, and by creating each checkedlistbox with the ammount of rows in my table, and by populating the checkedlistboxs with the data in the table. By itterating through all pf the checkedlistboxs i get all of the values that is checked and store them into another table.</p>
  
  <pre><code>private CheckedListBox[] Machines;
  
  Machines = new CheckedListBox[test.Length];
  int iLocation = 3;
  
          for (int i = 0; i &lt; Machines.Length; i++)
          {
              Machines[i] = new CheckedListBox();
              Machines[i].Name = "clb" + test[i].ToString();
  
              Machines[i].Location = new Point(iLocation, 6);
              Machines[i].Size = new Size(120, 139);
  
              iLocation += Machines[i].Width + 6;
  
  
              this.Controls.Add(Machines[i]);
          }
          Machines[2].Items.Add("Hello");
          Machines[2].Items.Add("Goodbye");
  </code></pre>
  
  <p>This code is for accessing data in the checked list box</p>
  
  <pre><code>ArrayList arrCheckedItems = new ArrayList();
          CheckedListBox.CheckedItemCollection objCheckedItem = Machines[2].CheckedItems;
          for (int i = 0; i &lt; objCheckedItem.Count; i++)
          {
  
              arrCheckedItems.Add(objCheckedItem[i]);
          }
          string[] srtArray = arrCheckedItems.ToArray(Type.GetType("System.String")) as string[];
          int iMachines = srtArray.Count();
          for (int i = 0; i &lt; iMachines; i++)
          {
              MessageBox.Show(srtArray[i].ToString());
          }
  </code></pre>