Fórum list box !!!! #180230
05/09/2003
0
como eu faço para quando eu adcionar um item ao list box ,o programa verificar se o item que eu quero incluir já está inclido no listbox e adiocionar somente se o item não já estiver incluido
obrigado
obrigado
Furla22
Curtir tópico
+ 0
Responder
Posts
06/09/2003
Demolitor
Eh simples, utilizei um Button, um ListBox e um Edit...
No evento OnClick do botão vc coloca o seguinte código...
:shock:
No evento OnClick do botão vc coloca o seguinte código...
procedure TForm1.Button1Click(Sender: TObject); var verifica: Boolean; i: Integer; begin verifica:= False; For i:=0 To Listbox1.Items.Count -1 Do begin If ListBox1.Items.Strings[i] = Edit1.Text Then verifica := True; End; If verifica = false Then Listbox1.Items.Append(Edit1.Text) Else ShowMessage( Edit1.Text + ´ já está na lista´); Edit1.Clear; Edit1.SetFocus; end;
:shock:
Responder
Gostei + 0
06/09/2003
Helbert
Bem eu uso uma função para para pesquisar se o valor já existe, e uma procedure para o restante do codigo.
procedure TF_TrabAcab.seqfinalExit(Sender: TObject); Var Maior:Integer; begin Maior:=0; if ((StrToInt(seqinicial.Text)) > 0 )then begin if PesquisaInt(FormatFloat(´000000´,(strtoint(seqinicial.Text)))) then begin ShowMessage(´Sequência já selecionada!´); end else begin if ((StrToInt(seqfinal.Text)) > 0) then begin if ((strtoint(seqfinal.Text)) < (strtoint(seqinicial.Text))) then begin ShowMessage(´Sequência inválida!´); end else begin DBListBox1.Items.Add(FormatFloat(´000000´,(strtoint(seqinicial.Text)))+ (´ a ´)+(FormatFloat(´000000´,(strtoint(seqfinal.Text))))); end; end else begin DBListBox1.Items.Add(FormatFloat(´000000´,(strtoint(seqinicial.Text)))); end; end; end; //*Guarga o maior valor digitado. if (DM_Modulo.TabLogin.State in [dsInsert, dsedit]) then begin with seqfinal do While ((strtoint(seqfinal.Text)) <> 0 ) do Begin Maior := (strtoint(seqfinal.Text)); if ((strtoint(seqfinal.Text)) > Maior ) then Maior := (strtoint(seqfinal.Text)); end; DM_Modulo.TabAcabSeqFinal.value :=Maior; end; //seqinicial.Text :=´´; //seqfinal.Text := ´´; seqinicial.SetFocus; seqinicial.SelectAll; end;
function TF_TrabAcab.PesquisaInt(Valor : String) : Boolean; var i : Integer; PosA : Integer; Ini : Integer; Fim : Integer; begin Result := False; for i := 0 to Pred(DBListBox1.Items.Count) do begin PosA := Pos(´a´,DBListBox1.Items[i]); if PosA > 0 then begin Ini := StrToInt(Copy(DBListBox1.Items[i],1,PosA-10)); Fim := StrToInt(Copy(DBListBox1.Items[i],PosA+10,Length(DBListBox1.Items[i]))); if (StrToInt(Valor) >= Ini) and (StrToInt(Valor) <= Fim) then begin Result := True; Break; end; end else begin if DBListBox1.Items[i] = Valor then begin Result := True; Break; end; end; end; end;
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)