Reputation: 1130
Im trying to add items left from a ListBox1 to ListBox2 preventing duplicate,I got the code from my question Prevent duplicate items in list box and combo box in Inno Setup? (works perfect passing one by one) and i whant to pass all items at this time pressing button ">>" (pass items left on ListBox1 to ListBox2 (no clone list box)).
here's the code:
procedure botonDerechaTodos(Sender: TObject);
begin
if (listBoxMonedasDisponibles.ItemIndex >= 0)then
begin
if listBoxMonedasSecundarias.Items.IndexOf(listBoxMonedasDisponibles.Items[listBoxMonedasDisponibles.ItemIndex]) < 0 then
listBoxMonedasSecundarias.Items.Add(listBoxMonedasDisponibles.Items[listBoxMonedasDisponibles.Items]);
listBoxMonedasDisponibles.Items.Delete(listBoxMonedasDisponibles.Items);
comboBoxMonedaPrincipal.Items := listBoxMonedasSecundarias.Items;
comboBoxMonedaPrincipal.ItemIndex := 0;
listBoxMonedasSecundarias.ItemIndex := 0;
end;
end;
Upvotes: 0
Views: 187
Reputation: 125748
Your code contains an error. You're passing Items
instead of ItemIndex
.
You have
listBoxMonedasSecundarias.Items.Add(listBoxMonedasDisponibles.Items[listBoxMonedasDisponibles.Items]);
It should be
listBoxMonedasSecundarias.Items.Add(listBoxMonedasDisponibles.Items[listBoxMonedasDisponibles.ItemIndex]);
You have a similar error here:
listBoxMonedasDisponibles.Items.Delete(listBoxMonedasDisponibles.Items);
It should be
listBoxMonedasDisponibles.Items.Delete(listBoxMonedasDisponibles.ItemIndex);
In response to the question asked in your comment, use AddStrings (I'm not typing all of those long variable names):
ListBoxDest.Items.AddStrings(ListBoxSource.Items);
ListBoxSource.Items.Clear;
Upvotes: 2