Recent

Author Topic: TreeView Refresh  (Read 5373 times)

BIT

  • Full Member
  • ***
  • Posts: 119
Re: TreeView Refresh
« Reply #15 on: September 18, 2021, 07:53:46 pm »
It would be helpful if you'd extract the critical part into a separate compilable project which you can upload here.
Do not forget to specify the path to your folder, otherwise it will load from 'C: \ WINDOWS \ System32 \'  Long.

BIT

  • Full Member
  • ***
  • Posts: 119
Re: TreeView Refresh
« Reply #16 on: September 18, 2021, 08:01:14 pm »
if you wave the mouse over the area that needs updating does it appear after that ?
Perhaps the problem is that I am passing LoadFileTreeViewPath (Form1.TreeView1);
and populate it in another unit.
PS: Possibly bad translation I hope you understand.

Change the focus via code to another control and back again...

MyOtherControl.SetFocus;
Application.ProcessMessages;
MyTreeview.SetFocus;
It didn't work that way. The general problem is when loading the form (FormCreate, FormShow). If you execute the code with Button it works fine.

wp

  • Hero Member
  • *****
  • Posts: 8907
Re: TreeView Refresh
« Reply #17 on: September 18, 2021, 10:56:16 pm »
Strange. Your code is correct (except for the missing TreeView.Items.BeginUpdate/EndUpdate which makes population of the tree so slow), and I've used similar code many times myself.

The only reason I could imagine is that populating the tree and selecting one of the last nodes are too close together, maybe to prepare scrolling for such a long list of items - I don't know.

Having this in mind I moved the population code into the OnCreate handler of the form and selected the last node later into the OnActivate or OnShow event. This way it works...

Code: Pascal  [Select][+][-]
  1. procedure TForm1.PopulateTree;
  2. begin
  3.   TreeView1.Items.BeginUpdate;
  4.   try
  5.     LoadFileTreeViewPath('C:\WINDOWS\System32\', TreeView1, nil, True);
  6.   finally
  7.     TreeView1.Items.EndUpdate;
  8.   end;
  9. end;
  10.  
  11. procedure TForm1.FormCreate(Sender: TObject);
  12. begin
  13.   FOnShowHandled := false;
  14.   PopulateTree;
  15. end;
  16.  
  17. procedure TForm1.FormShow(Sender: TObject);
  18. begin
  19.   if not FOnShowHandled then
  20.   begin
  21.     TreeView1.Select(TreeView1.Items[TreeView1.Items.Count - 1]);
  22.     FOnShowHandled := true;
  23.   end;
  24. end;

The boolean flag FOnShowHandled is supposed to prevent that the selection jumps to the end when OnShow is later executed again for some reason.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

jamie

  • Hero Member
  • *****
  • Posts: 4930
Re: TreeView Refresh
« Reply #18 on: September 18, 2021, 11:39:26 pm »
There is a regression..

 I added the TreeView1.BeginUpdate... which seems to be faster than using the Items.Update..

 It works perfectly fine over here with 2.0.4, 6 etc

 It appears that it refuses to update if the selected item is not going to show in the pane..

 the control has taken some changes at some point that broke this.

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 8907
Re: TreeView Refresh
« Reply #19 on: September 19, 2021, 12:31:57 am »
It works perfectly fine over here with 2.0.4, 6 etc
I don't have these versions any more. With 2.0.8, it does NOT work, but it DOES work with 1.8.4.

We should also check whether it works on Linux or mac to see wether the issue is in widgetset code.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

GAN

  • Sr. Member
  • ****
  • Posts: 338
Re: TreeView Refresh
« Reply #20 on: September 19, 2021, 03:22:06 am »
Works fine on Linux Mint 19.3 Mate (GTK). Lazarus 2.0.8 / FPC 3.0.4.
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

https://searchlazarus.blogspot.com/

BIT

  • Full Member
  • ***
  • Posts: 119
Re: TreeView Refresh
« Reply #21 on: September 19, 2021, 04:26:07 pm »
I'll try to load the TreeView in a separate thread, maybe something confuses when the form is loaded.

jamie

  • Hero Member
  • *****
  • Posts: 4930
Re: TreeView Refresh
« Reply #22 on: September 29, 2021, 01:41:55 am »
It seems there is a lock on the window update if the size of the window is the same as the last time an update to the window was requested.

 I am not sure if this is related to the Widget or LCL code but i had to do a hack to force an update to the combo box so that it would fully paint its border.

 I have seen code in the TControl I beleve or TWinControl that does check for the current size verses the changed size request coming in and if they are the same the request gets aborted. This may have something to do with it.

 In your OnResizeEvent which comes when the form is actually visible do this.

Code: Pascal  [Select][+][-]
  1. TreeView.Width := Treeview.Width-1;
  2. TreeView.Width := Treeview.Width+1;
  3.  
The first will be a different size than currently and allow for the control to refresh and the second puts it back to where it was.

This all happens during a cache update so there is no flicker but you should see  your TreeView display as you wish.

The only true wisdom is knowing you know nothing

BIT

  • Full Member
  • ***
  • Posts: 119
Re: TreeView Refresh
« Reply #23 on: October 07, 2021, 09:26:46 pm »
It seems there is a lock on the window update if the size of the window is the same as the last time an update to the window was requested.

 I am not sure if this is related to the Widget or LCL code but i had to do a hack to force an update to the combo box so that it would fully paint its border.

 I have seen code in the TControl I beleve or TWinControl that does check for the current size verses the changed size request coming in and if they are the same the request gets aborted. This may have something to do with it.

 In your OnResizeEvent which comes when the form is actually visible do this.

Code: Pascal  [Select][+][-]
  1. TreeView.Width := Treeview.Width-1;
  2. TreeView.Width := Treeview.Width+1;
  3.  
The first will be a different size than currently and allow for the control to refresh and the second puts it back to where it was.

This all happens during a cache update so there is no flicker but you should see  your TreeView display as you wish.
Thanks! I thought about it, how will I get back to the project and check it out.

 

TinyPortal © 2005-2018