Jump to content


Photo

OnApplyCell on NxDBDateColumn causing continous redraw


  • Please log in to reply
3 replies to this topic

#1 laurence

laurence
  • Members
  • 23 posts

Posted 31 May 2015 - 11:25 PM

Delphi 7, TNextDBGrid version 5.9.50

 

I have a NxDBDateColumn which I want to change the FormatDateMask depending on the cell value, as per this code:

 

procedure TfrmMain.gridActionsApplyCell(Sender: TObject; ACol, ARow: Integer; var Value: WideString);
var
  Field: TField;
begin
  if ACol = 0 then
  begin
    Field := gridActions.Columns[ACol].Field;
    if Assigned(Field) and (not Field.IsNull) then
      if Field.AsDateTime = DateOf(Field.AsDateTime) then
        NxDBDateColumn2.FormatDateMask := 'd mmm yyyy'
      else
        NxDBDateColumn2.FormatDateMask := 'd mmm yyyy h:nnam/pm';
  end;
end;
 
This formats the date correctly, however the grid is continously redrawing over and over. Is this because changing the FormatDateMask on the column is forcing a refresh of all rows? Is there a better way to do this? I have tried changing the Value but this throws an error of "Invalid Date".
 
Your help would be appreciated.
 
Laurence Bevan 
New Zealand
 


#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 01 June 2015 - 12:39 PM

Hi,

I think that better will be if you simly change Value parameter of event by your rules.

OnApplyCell is called while grid is drawing cells, so FormatDateMask is calling refresh once again and fall into recursion.

I hope that this helps.
boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 laurence

laurence
  • Members
  • 23 posts

Posted 02 June 2015 - 10:00 PM

Hi Boki,

 

I tried just changing the Value with this code:

 

procedure TfrmMain.gridActionsApplyCell(Sender: TObject; ACol, ARow: Integer; var Value: WideString);
var
  Field: TField;
begin
  if ACol = 0 then
  begin
    Field := gridActions.Columns[ACol].Field;
    if Assigned(Field) and (not Field.IsNull) then
      if Field.AsDateTime = DateOf(Field.AsDateTime) then
        Value := FormatDateTime('d mmm yyyy', Field.AsDateTime)
      else
        Value := FormatDateTime('d mmm yyyy h:nnam/pm', Field.AsDateTime);
  end;
end;
 
but I get invalid date errors. I think the formatting of the date field is happening after the OnApplyCell event has updated the Value.
 
Regards,
Laurence Bevan


#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 03 June 2015 - 10:54 AM

Hi,

 

Can you tell me which error you get?

 

Also, can you please try to set Value to some test value first and tell me if it appears inside cell. Maybe something is not correct in FormatDateTime part.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users