lamp

Implementing an Extension to Sort ControlCollection in .NET 3.5

Published 24 April 09 11:50 AM | Frederick.Chapleau

public static class SortingExtension
{
    public static void Sort<T>(this System.Windows.Forms.Control.ControlCollection c) where T : class
    {
        for(int i=1; i<c.Count; i++)
        {
            IComparable<T> ctl = cIdea as IComparable<T>;
            T pCtl = c[i - 1] as T;

            if (ctl != null && pCtl != null)
                if (ctl.CompareTo(pCtl) > 0)
                    c.SetChildIndex(cIdea, c.GetChildIndex(cIdea) - 1);
        }
    }
}

 

I will detailed a little more later this implementation.

-f.

Filed under:

Comments

# Frederick Chapleau .NET Tip of the Day said on April 24, 2009 11:54 AM:

Often, it is useful to compare object instances between them. The comparison is useful for many things

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Protected by FormShield
Refresh
Listen
Please enter the characters shown on the image


Code: