Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido)Mascara DbGrid


robinhocne

Pergunta

Em um DbGrid eu tenho uma coluna que recebe o valor de uma Query do Banco chamado (MovEntradaSaida) onde me retorna como E de Entrada ou S de Saida, então o que eu queria é que quando retornasse E podesse mostrar como Entrada e S mostrar como Saida, como faço isso ?

Editado por robinhocne
Link para o comentário
Compartilhar em outros sites

11 respostass a esta questão

Posts Recomendados

  • 0
Pelo que entendi você quer que na coluna do dbgrid mostre as legendas Entrada e Saida.

Se for, dê 2 ciques no controle, selecione o campo e va na propriedade Title e em Caption e coloque o que deseja

quando retornasse E podesse mostrar como Entrada e S mostrar como Saida, como faço isso ?

Isso eu sei fazer amigo, estou dizendo que na minha consulta na Query retorna no campo MovEntradaSaida como E para Entrada e S para Saida.....como mostra no Grid não lembro se o tratamento faz no Grid ou Query, pois se retorna do meu bando E eu quero que fica como Entrada e se me retorna S quero que fica como Saida

Link para o comentário
Compartilhar em outros sites

  • 0
dê um exemplo pratico, facilita a resposta dos seus colegas

abraço

No Banco de dados eu tenho o campo MovEntradaSaida, onde que E = Entrada e S = Saida;

Quando faço uma consulta no banco de dados

with QryBusca do
    begin
      close;
      sql.Clear;
      sql.Add(Instrucao);
      open;
    end;
E mostro o Resulta num DbGrid ela traz assim;
MovCodigo     MovDescricao     MovEntradaSaida
01                   VENDA                     S
02                   COMPRA                   E
03                   CONDICIONAL          S
em vez de mostra no DbGrid como S eu queria que mostrasse como Saida e ao invés de E mostrasse Entrada; já tentei colocar no After Scroll da Query
procedure TFAdmPes007.QryBuscaAfterScroll(DataSet: TDataSet);
begin
   if  QryBusca.FieldValues['MovEntradaSaida'] = 'S' then
     begin
         QryBusca.DisplayFormat := 'Saida';
     end
     else
     begin
         QryBusca.DisplayFormat := 'Entrada';
     end;

end;

mas dá certo....

Link para o comentário
Compartilhar em outros sites

  • 0

voce não disse qual é o banco de dados que esta usando, mas existe uma maneira que é usando um campo tipo boolean ou logical

exemplo:

CREATE DOMAIN T_BOOLEAN_CHAR CREATE DOMAIN T_BOOLEAN_CHAR 
AS CHAR(7) AS CHAR (7) 
DEFAULT 'ENTRADA' ENTRADA 'default' 
NOT NULL NOT NULL 
CHECK (VALUE IN ('E, 'S')) CHECK (VALUE IN ( 'ENTRADA', 'SAIDA'))

para esclarecer um pouco mais:

um campo tipo boolean ou logical, vai guardar na tabela os caracteres E e S , mas na propriedade ValueChecked voce vai digitar ENTRADA e na propriedade Value Unchecked voce vai digitar SAIDA

dessa forma será mostrada no dbgrid a palavra ENTRADA ou SAIDA conforme o caracter contido no campo E ou S

para maiores informações veja:

ValueChecked property (TDBCheckBox) no help do delphi

Delphi syntax:

property ValueChecked: String;

C++ syntax:

__property System::AnsiString ValueChecked = {read=FValueCheck, write=SetValueCheck};

Description

Use ValueChecked to specify the field value represented by the check box when it is checked. If the value of the ValueChecked property is equal to the data in the field of the current record of the dataset, the database check box appears checked. When the user checks the database check box, the field value is set to ValueChecked.

ValueChecked can represent more than one value in a semicolon-delimited list of items. If any of the items matches the contents of the field of the current record in the dataset, the check box appears checked. For example, set the value of ValueChecked string like this:

DBCheckBox1.ValueChecked := 'True;Yes;On';

DBCheckBox1->ValueChecked = "True;Yes;On";

If the contents of the associated field is the string true, Yes, or On, the check box is checked. The value of the field is compared to ValueChecked in a case-insensitive comparison. If the user selects a check box where ValueChecked represents more than one value, the first item in the list is assigned to the field.

If the contents of the field of the current record matches a string specified as the value of the ValueUnchecked property, the check box appears unchecked. If the contents of the field matches no string in either ValueChecked or ValueUnchecked, the check box appears gray.

Note: If the DataField of the database check box is a logical field, the check box is always checked if the contents of the field is true, and it is always unchecked if the contents of the field is false. The values of the ValueChecked and ValueUnchecked properties have no affect on logical fields.

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
voce não disse qual é o banco de dados que esta usando, mas existe uma maneira que é usando um campo tipo boolean ou logical

exemplo:

CREATE DOMAIN T_BOOLEAN_CHAR CREATE DOMAIN T_BOOLEAN_CHAR 
AS CHAR(7) AS CHAR (7) 
DEFAULT 'ENTRADA' ENTRADA 'default' 
NOT NULL NOT NULL 
CHECK (VALUE IN ('E, 'S')) CHECK (VALUE IN ( 'ENTRADA', 'SAIDA'))
para esclarecer um pouco mais: um campo tipo boolean ou logical, vai guardar na tabela os caracteres E e S , mas na propriedade ValueChecked voce vai digitar ENTRADA e na propriedade Value Unchecked voce vai digitar SAIDA dessa forma será mostrada no dbgrid a palavra ENTRADA ou SAIDA conforme o caracter contido no campo E ou S para maiores informações veja: ValueChecked property (TDBCheckBox) no help do delphi
Delphi syntax: property ValueChecked: String; C++ syntax: __property System::AnsiString ValueChecked = {read=FValueCheck, write=SetValueCheck}; Description Use ValueChecked to specify the field value represented by the check box when it is checked. If the value of the ValueChecked property is equal to the data in the field of the current record of the dataset, the database check box appears checked. When the user checks the database check box, the field value is set to ValueChecked. ValueChecked can represent more than one value in a semicolon-delimited list of items. If any of the items matches the contents of the field of the current record in the dataset, the check box appears checked. For example, set the value of ValueChecked string like this: DBCheckBox1.ValueChecked := 'True;Yes;On'; DBCheckBox1->ValueChecked = "True;Yes;On"; If the contents of the associated field is the string true, Yes, or On, the check box is checked. The value of the field is compared to ValueChecked in a case-insensitive comparison. If the user selects a check box where ValueChecked represents more than one value, the first item in the list is assigned to the field. If the contents of the field of the current record matches a string specified as the value of the ValueUnchecked property, the check box appears unchecked. If the contents of the field matches no string in either ValueChecked or ValueUnchecked, the check box appears gray. Note: If the DataField of the database check box is a logical field, the check box is always checked if the contents of the field is true, and it is always unchecked if the contents of the field is false. The values of the ValueChecked and ValueUnchecked properties have no affect on logical fields.
abraço
Eu utilizo o Firebird, porém no banco eu salvo mesmo somente como E para Entrada e S como Saida, porem eu tenho o meu retorno sempre S ou E......pois eu achava que daria certo, pois tipo para mostrar o valor em uma mascara eu faço assim:
procedure TFrmLivroCaixa.Query1AfterOpen(DataSet: TDataSet);
begin
  inherited;
   TFloatField(Query1.FieldByName('Valor')).DisplayFormat    := 'R$ #,##0.00';
end;

não daria para fazer algo parecido ?

Link para o comentário
Compartilhar em outros sites

  • 0

não daria para fazer algo parecido ?

acho qeu voce não entendeu a ideia ... veja como é simples

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if (Column.Field.FieldName = 'TIPO') then
      begin
         if Query1.FieldByName ('TIPO').AsBoolean = True then
            Query1TIPO.DisplayValues := 'Verdade'
         else
            Query1TIPO.DisplayValues := 'Falso';
      end;
end;
voce pode fazer a mesma coisa para E e S como foi feito para T ou F ( True ou False ) ou se o campo for do tipo VarChar(1)
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if (Column.Field.FieldName = 'TIPO') then
      begin
         if Query1.FieldByName ('TIPO').AsString = 'E' then
            Query1TIPO.DisplayValues := 'Entrada'
         else
            Query1TIPO.DisplayValues := 'Saida';
      end;
end;

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
não daria para fazer algo parecido ?

acho qeu voce não entendeu a ideia ... veja como é simples

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if (Column.Field.FieldName = 'TIPO') then
      begin
         if Query1.FieldByName ('TIPO').AsBoolean = True then
            Query1TIPO.DisplayValues := 'Verdade'
         else
            Query1TIPO.DisplayValues := 'Falso';
      end;
end;
voce pode fazer a mesma coisa para E e S como foi feito para T ou F ( True ou False ) ou se o campo for do tipo VarChar(1)
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
   if (Column.Field.FieldName = 'TIPO') then
      begin
         if Query1.FieldByName ('TIPO').AsString = 'E' then
            Query1TIPO.DisplayValues := 'Entrada'
         else
            Query1TIPO.DisplayValues := 'Saida';
      end;
end;

abraço

Tive que mudar da Query para uma Tabela temporária porem ela não tem essa propriedade, já tentei o DisplayText ou Label mas não deu certo, tem como fazer isso quando é para tabela temporária ?

Link para o comentário
Compartilhar em outros sites

  • 0
Tive que mudar da Query para uma Tabela temporária porem ela não tem essa propriedade, já tentei o DisplayText ou Label mas não deu certo, tem como fazer isso quando é para tabela temporária ?

se quiser usar Table no lugar da Query, o campo deverá ser do tipo logical ... e nesse caso a propriedade DisplayValues passara a existir para o Table.

abraço

Link para o comentário
Compartilhar em outros sites

  • 0
Tive que mudar da Query para uma Tabela temporária porem ela não tem essa propriedade, já tentei o DisplayText ou Label mas não deu certo, tem como fazer isso quando é para tabela temporária ?

se quiser usar Table no lugar da Query, o campo deverá ser do tipo logical ... e nesse caso a propriedade DisplayValues passara a existir para o Table.

abraço

Ok, resolvido

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...