tags:

views:

135

answers:

1

I was looking at http://delphi.about.com/od/tlistbox/a/list-box-onchange-drag-drop.htm and I was wondering if it would be possible to add the ability to disallow duplicate items like this, and if so how would I go and do it?

Thanks

-Brad

+3  A: 

To prevent duplicates in a list box, simply check whether the intended item exists in the list before you add it.

function ItemExists(ListBox: TListBox; const Item: string): Boolean;
begin
  Result := ListBox.Items.IndexOf(Item) >= 0;
end;

Call that function before you call Items.Add. If it returns True, don't call Items.Add.

Rob Kennedy
OMG, It's so simple.. why I didn't see it before! Thanks!
Brad