ComboBox Help

This is a discussion on ComboBox Help within the C# Programming forums, part of the General Programming Boards category; How do I make the items in the combo box appear in alphabetical order?...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    36

    ComboBox Help

    How do I make the items in the combo box appear in alphabetical order?

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,510
    You use google.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Code:
    List<object> items = new List<object>();
    
    foreach (object o in comboBox1.Items)
        items.Add(o);
    
    items.Sort((x, y) => x.ToString().CompareTo(y.ToString()));
    
    comboBox1.Items.Clear();
    comboBox1.Items.AddRange(items.ToArray());
    This is certainly one way of going about it, since I don't believe there are any built in sorting helpers in the ComboBox object.
    Last edited by theoobe; 05-24-2011 at 05:37 AM.

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,510
    There may be, if you are using windows.forms. Only works for a non data-bound combobox. Under WPF there aren't. The idea here being to sort before populating the control.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to use ComboBox's
    By bikr692002 in forum C++ Programming
    Replies: 2
    Last Post: 04-08-2006, 09:09 PM
  2. read-only combobox
    By hiya in forum Windows Programming
    Replies: 1
    Last Post: 06-08-2005, 07:32 AM
  3. Combobox problem
    By gargamel in forum Windows Programming
    Replies: 2
    Last Post: 05-06-2005, 01:37 PM
  4. Combobox help
    By Dohojar in forum Windows Programming
    Replies: 5
    Last Post: 04-15-2003, 07:02 AM
  5. Add String To Combobox?
    By (TNT) in forum Windows Programming
    Replies: 1
    Last Post: 09-15-2001, 04:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21