Jump to content


Photo

Added row displayed despite of BeginUpdate


  • Please log in to reply
6 replies to this topic

#1 czbird

czbird
  • Members
  • 58 posts

Posted 08 April 2014 - 01:04 PM

Hi, please run this simple procedure:

Grid.BeginUpdate;
Grid.ClearRows;

for i := 1 to 20 do begin
Grid.AddRow;
Application.ProcessMessages;
Sleep(100);
end;

Grid.EndUpdate;

As you can see, the first row gets displayed in the grid, although BeginUpdate was called before.
Other rows are added correctly (silently) and displayed after EndUpdate.

Please fix this problem.

(Using version 5.9.5)

#2 czbird

czbird
  • Members
  • 58 posts

Posted 08 April 2014 - 06:48 PM

Ok, it's not that simple, but in the end I managed to create a sample project; please see the attachment.
And version 5.9.9 behaves the same (just updated).
The issue is somehow connected with hiding a panel component covering the grid in case the grid is empty.

Here is the whole code:


procedure TForm1.Button1Click(Sender: TObject);
var
i : Integer;
begin
Grid.BeginUpdate;

for i := 1 to 10 do begin
Grid.AddRow;
Grid.Cell[0, Grid.LastAddedRow].AsInteger := 0;
Grid.Cell[1, Grid.LastAddedRow].AsString := IntToStr(Grid.RowCount);
Grid.Cell[2, Grid.LastAddedRow].AsString := 'some text';
Application.ProcessMessages;
Sleep(100);
end;

Grid.EndUpdate;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Form1.Close;
end;

procedure TForm1.ClearClick(Sender: TObject);
begin
Grid.ClearRows;
end;

procedure TForm1.GridDataChange(Sender: TObject; AChangeType: TDataChange;
const AIndex: Integer);
begin
if AChangeType in [dcAddRow, dcInsertRow, dcDeleteRow, dcClearRows] then
EmptyGridPanel.Visible := Grid.RowCount = 0;
end;


#3 czbird

czbird
  • Members
  • 58 posts

Posted 08 April 2014 - 06:51 PM

Here comes the sample project (XE5).

Attached Files



#4 czbird

czbird
  • Members
  • 58 posts

Posted 15 April 2014 - 11:20 AM

Boki, would you please respond...

#5 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted 16 April 2014 - 10:39 PM

Hi,

Please sorry for my delay.

It seems that Panel you placed over grid causes repaint (WM_PAINT message).

Maybe you can add next line in Paint procedure:

procedure TNxCustomGridControl.Paint;
var
  CaptionRect: TRect;
begin
  inherited;

  if UpdateCount > 0 then Exit; // <------ New line

Please tell me how this work. I hope that I will not ruin anything with it. I will need to check it more.
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.

#6 Boki (Berg)

Boki (Berg)

    Boki (Berg)

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

Posted 16 April 2014 - 10:41 PM

PS. if this fix work for you, I need to update EndUpdate method too (easy fix).
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.

#7 czbird

czbird
  • Members
  • 58 posts

Posted 03 May 2014 - 11:35 PM

Hi Boki, this seems to be working just fine. Thanks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users