Fórum evitar duplicidade no combobox #351384
04/01/2008
0
tentei trabalhar com o metodo IndexOf mas nao cheguei a lugar algum...
abraços!
Mahdak
Curtir tópico
+ 0Posts
04/01/2008
Pestana_
agora para evitar duplicidade no proprio combo eu não sei.
flw.
Gostei + 0
04/01/2008
Pestana_
se eu não me engano o [i:b5bb6efdb5]IndexOf[/i:b5bb6efdb5] retorna o indice do item.
Gostei + 0
05/01/2008
Jose Almeida
Use esta função:
function StrIsInList(Lista:TStrings;Str:string): boolean;
var
Cont:integer;
begin
Result:=false;
for Cont:=0 to Lista.Count-1 do
if Str = (Lista.Strings[Cont])then
begin
Result:=true;
Exit;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if not(StrIsInList(ComboBox1.Items,Edit1.Text)) then
ComboBox1.Items.Add(Edit1.Text);
end;
Se o String não está no ComboBox, então adiciona.
Gostei + 0
07/01/2008
Micheus
procedure TForm1.ComboBox1Exit(Sender: TObject); begin if ComboBox1.Items.IndexOf(ComboBox1.Text) = -1 then ComboBox1.Items.Add(ComboBox1.Text); end;
Gostei + 0
08/01/2008
Pestana_
procedure TForm1.ComboBox1Exit(Sender: TObject); begin if ComboBox1.Items.IndexOf(ComboBox1.Text) = -1 then ComboBox1.Items.Add(ComboBox1.Text); end;
boa [b:0858c9c199]micheus[/b:0858c9c199] deste jeito resolve o problema do mahdak.
flw.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)