ArisRS
ArisRS

Reputation: 1394

C# Combobox move item to bottom of the list

I need to add "Select more..." to the bottom of the combobox items, like it done on SQL 2008 servers selector. Trying like this:

        List<string> srvList = new List<string>();
        srvList.Add("ff");
        srvList.Add("jj");
        srvList.Add("pp");
        srvList.Add("<Select more...>");
        ComboBoxServs.Items.AddRange(srvList.ToArray<String>());

But "Select more..." appears at the top of items.

Upvotes: 5

Views: 2650

Answers (2)

dotmido
dotmido

Reputation: 1382

You have to use the index of Insert method of Combobox control

 myComboBox.Items.Insert(0, "Select more");

hope that help. you may Refer Here also

Upvotes: 0

Andrey Gordeev
Andrey Gordeev

Reputation: 32559

As MSDN says:

If the Sorted property of the ComboBox is set to true, the items are inserted into the list alphabetically. Otherwise, the items are inserted in the order they occur within the array.

Try to set Sorted property to false:

    ComboBoxServs.Sorted = false;
    List<string> srvList = new List<string>();
    srvList.Add("ff");
    srvList.Add("jj");
    srvList.Add("pp");
    srvList.Add("<Select more...>");
    ComboBoxServs.Items.AddRange(srvList.ToArray<String>());

Upvotes: 3

Related Questions