Recent

Author Topic: DBgrid and event on cells ??  (Read 1871 times)

Fabius

  • New Member
  • *
  • Posts: 40
DBgrid and event on cells ??
« on: June 10, 2021, 05:38:52 pm »
Hello

Do you know a DBgrid for Lazarus with event (enter, exit ...) on the cells? :)

bpranoto

  • Full Member
  • ***
  • Posts: 103
Re: DBgrid and event on cells ??
« Reply #1 on: June 10, 2021, 06:20:47 pm »
TDBGrid has onColEnter and onColExit.

You can use them  and the dataset afterScroll event to detect cell position changes.

Fabius

  • New Member
  • *
  • Posts: 40
Re: DBgrid and event on cells ??
« Reply #2 on: June 10, 2021, 06:27:28 pm »
Yes I know, I try to make it work, but it's not good for me

I am looking for a dbgrid more evolve than that of the IDE

Code: Pascal  [Select][+][-]
  1.  
  2. procedure TForm3.DBGrid1ColExit(Sender: TObject);
  3. var Xcompte : string;
  4. var Xlabel : string;
  5. Var MontantTMtv : extended;
  6.  
  7. begin
  8.  
  9.     if DBGrid1.SelectedField.FieldName = 'CREDIT' then
  10.     begin
  11.     StatusBar1.SimpleText := 'Champ Credit';
  12.     if ((DBGrid1.Columns[3].Field.Value > 0) AND (DBGrid1.Columns[2].Field.Value > 0) ) Then
  13.     begin
  14.     MontantTMtv :=  DBGrid1.Columns[2].Field.Value;   ////credit
  15.     Form1.Xsaisie.Edit;
  16.     Form1.Xsaisie.FieldByName('credit').AsFloat :=MontantTMtv;
  17.     Form1.Xsaisie.FieldByName('debit').AsFloat :=0;
  18.     Form1.Xsaisie.Post;
  19.     Form1.Xsaisie.Refresh;
  20.     DBGrid1.Refresh;
  21.     end;
  22.  
  23.     DBGrid1.SelectedColumn.FieldName := 'DEBIT';
  24.       calcullignes;
  25.  
  26.     end;
  27.  
  28.  
  29.  
  30.  

Fabius

  • New Member
  • *
  • Posts: 40
Re: DBgrid and event on cells ??
« Reply #3 on: June 10, 2021, 06:39:36 pm »
I test also

But not Ok



Code: Pascal  [Select][+][-]
  1. procedure TForm3.DBGrid1ColExit(Sender: TObject);
  2. var Xcompte : string;
  3. var Xlabel : string;
  4.  
  5.  
  6. begin
  7.  
  8.     if DBGrid1.SelectedField.FieldName = 'CREDIT' then ///////credit en premier
  9.     begin
  10.       StatusBar1.SimpleText := 'Champ Credit';
  11.       if ((DBGrid1.Columns[2].Field.Value > 0) AND (DBGrid1.Columns[3].Field.Value > 0) ) Then
  12.       begin
  13.       DBGrid1.Columns[3].Field.Value := 0;
  14.       end;
  15.     end;
  16.  
  17.  
  18.  
  19.  
  20.       if DBGrid1.SelectedField.FieldName = 'DEBIT' then //////////Debit priorite
  21.       begin
  22.         if ((DBGrid1.Columns[3].Field.Value > 0) AND (DBGrid1.Columns[2].Field.Value > 0) ) Then    ///////////debit
  23.         begin
  24.          DBGrid1.Columns[2].Field.Value := 0;
  25.  
  26.         end;
  27.  
  28.  
  29.        end;

bpranoto

  • Full Member
  • ***
  • Posts: 103
Re: DBgrid and event on cells ??
« Reply #4 on: June 10, 2021, 07:00:16 pm »
Yes I know, I try to make it work, but it's not good for me

What do you mean with "not good"?  Is the event not fired?

Fabius

  • New Member
  • *
  • Posts: 40
Re: DBgrid and event on cells ??
« Reply #5 on: June 11, 2021, 06:10:25 am »
Hello
So of course the event is triggered!  :)

but the manipulation of the fields does not give the good result that I hope

If it is the last column (debit), the previous field (credit) is not set to zero

if DBGrid1.SelectedField.FieldName = 'DEBIT' then //////////Debit priorite
      begin
        if ((DBGrid1.Columns[3].Field.Value > 0) AND (DBGrid1.Columns[2].Field.Value > 0) ) Then    ///////////debit
        begin
         DBGrid1.Columns[2].Field.Value := 0;
 
        end;
 
 
       end;


And the rows all become the same (mix of rows)

I tried to act on the dataset, same thing ...

The Dbgrid is recalcitrant

 

TinyPortal © 2005-2018