Search code examples
comboboxlazarusfreepascal

TComboBox: add items in "reversed order"


TComboBox.Items.Add adds an item "at the end" of the list (at n+1 with n being the last index before edding the new item):

0: Item1
1: Itme2
2: Item3
3: New Item

But I want to add the item at n=0, with all the other items moving up one index:

0: New Item
1: Item1
2: Itme2
3: Item3

Currently I'm using this code, which works well:

ComboBox1.Items.Add(strSomeNewItem);
ComboBox1.Items.Move(ComboBox1.Items.Count-1,0);

I was just wondering if I overlooked a scenario in which it might cause problems?! Or maybe there is a better command I overlooked?! (The Lazarus Component Library is currently down, so most of the links in my search engine come up with an error).

Cheers!


Solution

  • You can use Insert().

    ComboBox1.Items.Insert(0, strSomeNewItem);