title: Form control change to runtime object VB.net
body: <p>I have a form what contains about 10-15 <code>CheckedListBox</code> objects on a <code>Panel</code> named <code>PanelFilterBoxes</code>.
  Each <code>CheckedListBox</code> can contains lots of items (1 to max ~2000).</p>
  
  <p>I have to reload regulary the items of this controls based upon a datatable's column unique values (plus some extras).</p>
  
  <p>Now I have a code like this (this below is just a shorten extract):</p>
  
  <pre><code>For c = 0 To PanelFilterBoxes.Controls.Count - 1
      '--get unique datas from datatable 
      Dim dtUnique() As String = ....
  
      '--change items of the control
      Dim contr As CheckedListBox = PanelFilterBoxes.Controls.Item(c)
      contr.Items.Clear()
      contr.Items.Add("*All", True)
      contr.Items.Add("*Search: ", False)
  
      For Each myValue As String In dtUnique
          '--add items with checked true
          contr.Items.Add(myValue, True)
      Next
  
  Next
  </code></pre>
  
  <p>It is not so long, but takes some times. I'd like to try what if I create a runtime object (<em>I can put data in a runtime created object faster than a form object</em>), and "replace" the control on the form with this?</p>
  
  <p>So my "big challenge" how can I do this?</p>
  
  <p>I tried this ways, but not works :/</p>
  
  <pre><code>For c = 0 To PanelFilterBoxes.Controls.Count - 1
      '--get unique datas from datatable 
      Dim dtUnique() As String = ....
  
      '--change items of the control
      Dim contr As CheckedListBox = PanelFilterBoxes.Controls.Item(c)
  
      '--runtime temporary object
      Dim tempContr As new CheckedListBox
  
      contr.Items.Clear()
  
      tempContr .Items.Add("*All", True)
      tempContr .Items.Add("*Search: ", False)
  
      For Each myValue As String In dtUnique
          '--add items with checked true
          tempContr .Items.Add(myValue, True)
      Next
  
      '--1 - this doesn't works, but doesn't produce any error
      contr=tempContr
  
      '--2 - it works, but the items aren't checked
      contr.Items.AddRange(tempContr.Items)
  
  Next
  </code></pre>
  
  <p>Anybody has a solution for this?</p>
  
  <p>Thank you</p>