0

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)). enter image description here

and get this on buttonClick enter image description here

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;

1 Answers1

2

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;
Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Doesn't work for what I want, I already use that code you say without problem to button ">" (passing item one by one), but i want to add(pass) all items left from listBoxMonedasDisponibles to listBoxMonedasSecundarias to make button ">>"(Passing all). is there any way to modify to do that? – Angel Montes de Oca May 25 '17 at 18:27
  • Thank you so much, I really apreciated. – Angel Montes de Oca May 25 '17 at 18:39