PAGUE 6 MESES
LEVE 12 MESES
GARANTIR DESCONTO

Fórum Obter retorno do ComboBox? #407600

13/09/2011

0

Pessoal tenho um combobox com itens concatenados Telefone + Nome que vem de numa tabela.

Ai o usuario deverá buscar o cliente tanto digitando na caixa de texto do combobox por TELEFONE ou por NOME

E deve retornar na caixa de texto os campos.

Quando digito pelo telefone que é pelo primeiro que esta na lista de itens quando acha retorna os dois campos, ja quando busco pelo nome na caixa de texto retorna só o nome na caixa de texto, e preciso que retorne os dois campos.

O codigo que estou usando no onchange do combo é este procedure que esta chamando
procedure TfrmVendasRapidas.cbClientesPropertiesChange(Sender: TObject);
begin
  inherited;
  UpdateComboBox(cbClientes);
end;


A procedure que estou usando é esta aqui
//função para buscar depois do delimiters imposto pela barra observar os espaços entre a barra no const
function ScanListCombo(S: string; Lista: TStrings; CaseInSensitive: Boolean): Integer;
const
  Separador = ' = ';
  LenSeparador = Length(Separador);
var
  I, P: Integer;
  Item, SC: String;
begin
  Result := -1;
  if S = EmptyStr then
    Exit;

  for I := 0 to Pred(Lista.Count) do
  begin
    Item := Lista[I];
    P := Pos(Separador, Item);
    if P > 0 then
    begin
      Item := Copy(Item, P + LenSeparador, Length(S));

      if not CaseInSensitive then
      begin
        if S = Item then
        begin
          Result := I;
          Exit;
        end;
      end
      else
      if SameText(S, Item) then
      begin
        Result := I;
        Exit;
      end;
    end;
  end;
end;


procedure UpdateComboBox(ComboBox: TcxComboBox);
const
  Separador = ' = ';
  LenSeparador = Length(Separador);
var
  I, L : Integer;
  S : string;
begin
  I := ScanListCombo(ComboBox.Text, ComboBox.Properties.Items, True);
  if I > -1 then
  begin
    S := ComboBox.Properties.Items[I];
    L := Pos(Separador, S);
    if L > 0 then
    begin
      Delete(S, 1, L + LenSeparador - 1);
      L := ComboBox.SelStart;
      ComboBox.Text := S;
      ComboBox.SelStart := L;
      ComboBox.SelLength := Length(S)-L;
    end;
  end;
end;
Adriano Dolce

Adriano Dolce

Responder

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar