Nicolò Blunda 3 Posted December 21, 2024 Hi. I would like to sort the elements in a ComboEdit in the exact order of typing. That is... the combo should save the typing history of the inserted elements, with the last element in first position and so on... I don't see the sorted property to set the order of all the elements/items, which are, by default, sorted alphabetically. How can I do that? Share this post Link to post
Nicolò Blunda 3 Posted December 21, 2024 Find solution. Method "Append" instead "Add" can include new item at the top of drop list. Share this post Link to post
Pat Foley 52 Posted December 21, 2024 What keys or click did you use to connect the append. Under windows code seems to add a line when tabbed? // if you wire up onClick In Events in Object Inspector procedure TForm13.ComboEdit1Click(Sender: TObject); begin if Sender is TComboEdit then begin var CE := Sender as TComboEdit; CE.Items.Insert(0, CE.text); //CE.Items.add(CE.Text); //CE.Items.Insert(CE.Items.Count, CE.text); CE.Text := ''; //clears for newline end; end; 1 Share this post Link to post
Typer2 0 Posted January 7 On 12/21/2024 at 8:51 AM, Nicolò Blunda said: I don't see the sorted property to set the order of all the elements/items, which are, by default, sorted alphabetically. How can I do that? Actually TComboEdit.Lines is not sorted by default and you need to leave it that way if you want to control the order of the items. On 12/21/2024 at 3:58 PM, Nicolò Blunda said: Find solution. Method "Append" instead "Add" can include new item at the top of drop list. I find it hard to believe this solved your problem, as Append is the same as the Add method, except that it does not return a value. So I suspect you meant Insert(0, aText); I use a helper class for this: TComboEditHelper = class helper for TComboEdit public procedure StoreText; end; procedure TComboEditHelper.StoreText; var vText: string; vI: Integer; begin vText := Text; if not vText.IsEmpty then begin vI := Items.IndexOf(vText); if vI > -1 then begin Items.Delete(vI); Items.Insert(0, vText); Text := vText; end else begin Items.Insert(0, vText); end; // At most 15. if Items.Count > 15 then Items.Delete(15); end; end; Share this post Link to post