Recent

Author Topic: DBgrid celules  (Read 3267 times)

Fabius

  • Jr. Member
  • **
  • Posts: 59
DBgrid celules
« on: June 10, 2021, 04:38:49 pm »
Hello everyone

I have the following problem

in a DBgrid I have two columns

I want only one of the two columns to be greater than zero, at user input

I did this, but it doesn't work for the last DEBIT field

Do you have an idea ?

Code: Pascal  [Select][+][-]
  1.     if DBGrid1.SelectedField.FieldName = 'CREDIT' then
  2.     begin
  3.     StatusBar1.SimpleText := 'Champ Credit';
  4.       if DBGrid1.Columns[2].Field.Value > 0 Then
  5.       begin
  6.       DBGrid1.Columns[3].Field.Value := 0; ///////////debit   OK this OK the field ZERO
  7.       ///DBGrid1.DataSource.DataSet.Last();
  8.       end;
  9.       calcullignes;
  10.  
  11.     end;
  12.  
  13.  
  14.  
  15.     if DBGrid1.SelectedField.FieldName = 'DEBIT' then
  16.     begin
  17.  
  18.       if DBGrid1.Columns[3].Field.Value > 0 Then  //////////champ debit
  19.       begin
  20.      
  21.       DBGrid1.Columns[2].Field.Value := 0;  ////////credit  NOT to ZERO ??
  22.  
  23.       StatusBar1.SimpleText := 'Credit A zero ';   ///ok
  24.       end;
  25.       calcullignes;
  26.  
  27.     end;  

« Last Edit: June 10, 2021, 05:09:53 pm by Fabius »

bpranoto

  • Full Member
  • ***
  • Posts: 134
Re: DBgrid celules
« Reply #1 on: June 10, 2021, 07:26:08 pm »
Do the job on the OnChange of the fields.

Code: Pascal  [Select][+][-]
  1. // Apply this to the OnChange event of the field DEBET
  2. procedure TForm1.Dataset1debetChange(Sender: TField);
  3. begin
  4.   if Sender.AsFloat > 0 then begin
  5.     DataSet.FieldByName('CREDIT').AsFloat := 0;
  6.   end;
  7. end;
  8.  
  9. // Apply this to the OnChange event of the field CREDIT
  10. procedure TForm1.Dataset1kreditChange(Sender: TField);
  11. begin
  12.   if Sender.AsFloat > 0 then begin
  13.     DataSet.FieldByName('DEBET').AsFloat := 0;
  14.   end;
  15. end;

« Last Edit: June 10, 2021, 07:28:07 pm by bpranoto »

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: DBgrid celules
« Reply #2 on: June 11, 2021, 06:19:19 am »
Hello

No onchange event on the dbgrid fields?

If there was it would be great

Or have I not seen ??

Of course I could link the table to dbedit and modify by them

but I am trying to modify by the dbgrid

it is an accounting software and i would like to enter the values ​​in the dbgrid


bpranoto

  • Full Member
  • ***
  • Posts: 134
Re: DBgrid celules
« Reply #3 on: June 11, 2021, 09:15:08 am »
Hello

No onchange event on the dbgrid fields?


The event is not on the TDBGrid (..and TDBGrid of course doesn't have fields).

It is on the Dataset fields.

bpranoto

  • Full Member
  • ***
  • Posts: 134
Re: DBgrid celules
« Reply #4 on: June 11, 2021, 09:39:41 am »
Here is a simple demo.

Is this what you want?

Fabius

  • Jr. Member
  • **
  • Posts: 59
Re: DBgrid celules
« Reply #5 on: June 11, 2021, 02:42:01 pm »
Thank You , I test  :)

 

TinyPortal © 2005-2018