Jump to content

How To Blank Grid Cell When The Value Is Zero?


Frederick

Recommended Posts

In a TUniDBGrid, I want a cell to show a blank value when the field of the data source linked to it is 0.00. 

I am using the following event of the grid but the cell still shows the zero.

procedure TForm.grdGridSetCellValue(Sender: TObject; ACol, ARow: Integer;
  AField: TField; var Value: Variant);
begin
   if Afield.FieldName='debit' then begin
      if Value='0.00' then
         Value:='';
   end;
end;

What am I missing here or is this the correct event to use?

--
Frederick
(UniGUI Complete - Professional Edition 1.90.0.1530)
 

Link to comment
Share on other sites

6 hours ago, Freeman35 said:

Hi,

You can use TField.DisplayFormat:= ',#.##';

Thanks for the post.

I solved the problem as follows:-

1.   Set the field's DisplayFormat to '#,0.00;-#,0.00; ' (There is a space after the second semi colon) and

2.   Add the following code in the field's OnGetText event

procedure TUniMainModule.qryObcreditGetText(Sender: TField; var Text: string;
  DisplayText: Boolean);
begin
   Text := FormatFloat( TNumericField( sender ).DisplayFormat , Sender.Value );
end;

The setting of the DisplayFormat property is the same as I would use in a Delphi Windows program but for some reason in UniGUI, the setting is not recognized and rubbish characters are shown in TUniDBGrid if the OnGetText event is blank.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...