title: Ordering Controls inside FlowLayoutpanel
body: <p>I have a <code>Windows.Forms.FlowLayoutPanel</code> that is being filled at runtime with controls of the type <code>MasterMeter</code> (and controls inheriting from MasterMeter). This is your standard <code>Usercontrol</code>. Each of those controls has a property <code>ErrorTime</code>. This value keeps the duration of the current error or alert.</p>
  
  <pre><code> Datetime? ErrorTime {get; set;}
  </code></pre>
  
  <p>I'm currently trying to order the controls using the <code>bubblesort-method</code> based on the duration of the error (descending).  Right now I was wondering is there a faster/more performant/more reliable way to do this?</p>
  
  <p>If not, is there another container i could be using? 
  It needs to have the following caracteristics:</p>
  
  <ul>
  <li>Amount of items may vary</li>
  <li>Amount of items at runtime may change from 0 to 100 (never had more than 100 errors before...)</li>
  <li>Must be able to contain usercontrols</li>
  </ul>
  
  <p><strong>Current Code (that won't sort)</strong></p>
  
  <p>I'm using a 1D-Array to keep it simple (in reality its a jagged Array).
  Note: The possibilty of <code>NULL</code> values</p>
  
  <pre><code>MasterMeter[] meterList = {new MasterMeter() { ErrorTime = null },
                             new MasterMeter() { ErrorTime = DateTime.Now },
                             new MasterMeter() { ErrorTime = DateTime.Now.AddDays(-10) },
                             new MasterMeter() { ErrorTime = DateTime.Now.AddDays(37) },
                             new MasterMeter() { ErrorTime = DateTime.Now.AddDays(53) },
                             new MasterMeter() { ErrorTime = DateTime.Now.AddDays(3) },
                             new MasterMeter() { ErrorTime = null },
                             new MasterMeter() { ErrorTime = DateTime.Now.AddDays(-17) },
                             new MasterMeter() { ErrorTime = DateTime.Now.AddDays(-10) },
                             new MasterMeter() { ErrorTime = null }
                            };
  </code></pre>
  
  <p>I'm <code>Bubblesorting</code> as follows:</p>
  
  <pre><code>        for (int outer = 0; outer &lt; meterList.Count(); outer++)
          {
              for (int inner = 0; inner &lt; (meterList.Count() - 1); inner++)
              {
                  if (meterList[inner].ErrorTime &gt; meterList[inner + 1].ErrorTime)
                  {
                      var temp = meterList[inner + 1];
                      meterList[inner + 1] = meterList[inner];
                      meterList[inner] = temp;
                  }
              }
          }
  </code></pre>
  
  <p>My ouput result (Using <code>Console.Writeline</code>):</p>
  
  <pre><code>        foreach (MasterMeter meterlist in meterList)
          {
              Console.WriteLine(meterlist.ErrorTime);
          }
          Console.ReadLine();
  </code></pre>
  
  <p>But my array still isn't sorted. What is going wrong here?</p>