Components for Delphi and C++ Builder.

Go to Russian forum
Go to EhLib.com
It is currently 28 Mar 2024, 23:48

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: 17 Oct 2022, 07:09 
Offline

Joined: 13 Oct 2022, 10:01
Posts: 7
Hi, I have recently used DBGridEh ... I wanted to ask ...

I am defining the options of my grid, but I need that when editing,
it only allows the user to enter 2 decimal places, how can I achieve it?

you can help me ?
thanks in advance
Roberto


Top
 Profile  
 
PostPosted: 17 Oct 2022, 07:31 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Hello

I didn't fully understand the question.
Do you need to set up a grid column so that the user can enter no more than two decimal characters in an edit cell?

_________________
Best regards
EhLib Support Team


Top
 Profile  
 
PostPosted: 17 Oct 2022, 07:44 
Offline

Joined: 13 Oct 2022, 10:01
Posts: 7
thanks for your answer ...
yes, the user must not be able to enter numbers with more than two decimals in a cell
1256,89 is fine
1256,897 is not good
Thank you
Roberto


Top
 Profile  
 
PostPosted: 17 Oct 2022, 07:45 
Offline

Joined: 13 Oct 2022, 10:01
Posts: 7
thanks for your answer ...
yes, the user must not be able to enter numbers with more than two decimals in a cell
1256,89 is fine
1256,897 is not good
Thank you
Roberto


Top
 Profile  
 
PostPosted: 17 Oct 2022, 07:50 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Do you want to give an error message or round to two decimal places?

_________________
Best regards
EhLib Support Team


Top
 Profile  
 
PostPosted: 17 Oct 2022, 07:58 
Offline

Joined: 13 Oct 2022, 10:01
Posts: 7
No message ... just prevent other digits from being entered ....
if I write 1234,567 .. the last digit (7) I don't have to be able to write it
thank you


Top
 Profile  
 
PostPosted: 17 Oct 2022, 18:23 
Offline

Joined: 08 May 2014, 18:06
Posts: 660
Hello
I think Grid editor does not support this feature.

You can round a number to the second decimal place when the user presses Enter and the editor closes.
You can use TColumn.OnUpdateData event like this

Code:
procedure TForm1.DBGridEh1Columns5UpdateData(Sender: TObject; var Text: string;
  var Value: Variant; var UseText, Handled: Boolean);
begin
  Text := RoundTo(Extended.Parse(Text), -2).ToString;
end;

_________________
Best regards
EhLib Support Team


Top
 Profile  
 
PostPosted: 18 Oct 2022, 15:36 
Offline

Joined: 13 Oct 2022, 10:01
Posts: 7
Thanks for your reply, but rounding up for my needs is not good.

I found and edited the following code and placed it in the grid's onkeypress event.

I declared the class
type TFooDBGrid = class (TDBGrideh);

in the onkeypress event of the grid I inserted the following code
const
MAXNUMBEROFDIGITS = 2;
var
S: string;
val: Double;
n: Integer;
begin
// ****
if key <> # 8 then
S: = '';
if (GridEh_Listino.EditorMode) and (GridEh_Listino.SelectedField.FieldName = 'QtaMinima')
or (GridEh_Listino.SelectedField.FieldName = 'Discount1')
or (GridEh_Listino.SelectedField.FieldName = 'Discount2')
or (GridEh_Listino.SelectedField.FieldName = 'Discount3')
then begin
if key in ['0' .. '9', '-', ',']
then begin
S: = TFooDBGrid (GridEh_Listino) .InplaceEditor.EditText;

if TFooDBGrid (GridEh_Listino) .InplaceEditor.SelLength> 0 then
Delete (S, TFooDBGrid (GridEh_Listino) .InplaceEditor.SelStart + 1, TFooDBGrid (GridEh_Listino) .InplaceEditor.SelLength);
Insert (key, S, TFooDBGrid (GridEh_Listino) .InplaceEditor.SelStart + 1);

try
val: = StrToFloat (S);
n: = Pos (',', S);
if n> 0 then
if (Length (S) - n)> MAXNUMBEROFDIGITS then
key: = # 0;
except
key: = # 0;
end;
end;
end
else
key: = # 0;
// ***

All this prevents you from writing other digits beyond two decimals.
I hope it can be of help to someone

Best regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group