Recent

Author Topic: how can i select all items of Level?  (Read 3282 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
how can i select all items of Level?
« on: June 24, 2017, 07:59:00 pm »
Hi
.
i have a treeview.
.
how can i print all of red color items in a memo??(or green color items or blue ....)

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how can i select all items of Level?
« Reply #1 on: June 24, 2017, 10:45:40 pm »
there you go a bit better version of the text based selection.
Code: Pascal  [Select][+][-]
  1. procedure SelectNodeByText(const aTreeView:TTreeView; aNodelevel:Integer);
  2. var
  3.   vNode     : TTreeNode = nil;
  4.   vLastNode : TTreeNode = nil;
  5. begin
  6.   for vNode in aTreeView.Items do begin
  7.     if vNode.Level = aNodelevel then begin
  8.       vLastNode := vNode;
  9.       vNode.Selected := True;
  10.       if not aTreeView.MultiSelect then Break;
  11.     end;
  12.   end;
  13.   if Assigned(vLastNode) then vLastNode.Focused := True;
  14. end;
  15.  
As always no cpu or compiler was harmed.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: how can i select all items of Level?
« Reply #2 on: June 25, 2017, 12:00:24 am »
Here's an example.

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: how can i select all items of Level?
« Reply #3 on: June 27, 2017, 01:23:29 am »
there you go a bit better version of the text based selection.
Code: Pascal  [Select][+][-]
  1. procedure SelectNodeByText(const aTreeView:TTreeView; aNodelevel:Integer);
  2. var
  3.   vNode     : TTreeNode = nil;
  4.   vLastNode : TTreeNode = nil;
  5. begin
  6.   for vNode in aTreeView.Items do begin
  7.     if vNode.Level = aNodelevel then begin
  8.       vLastNode := vNode;
  9.       vNode.Selected := True;
  10.       if not aTreeView.MultiSelect then Break;
  11.     end;
  12.   end;
  13.   if Assigned(vLastNode) then vLastNode.Focused := True;
  14. end;
  15.  
As always no cpu or compiler was harmed.

Hi
sorry for late.
.
this code doesn't work correctly?!?!
.
??
i change your code to this and it work
thankyou

Code: Pascal  [Select][+][-]
  1. procedure SelectNodeByText(const aTreeView:TTreeView; aNodelevel:Integer);
  2. var
  3.   i:Integer;
  4. begin
  5.   for i := 0 to aTreeView.Items.Count -1 do  begin
  6.     if( aTreeView.Items[i].Level = aNodelevel)then
  7.     FormMain.Memo2.Lines.Add( aTreeView.Items[i].Text);
  8.   end;
  9.  
  10. end;
  11.  
« Last Edit: June 27, 2017, 01:52:45 am by majid.ebru »

frederic

  • Full Member
  • ***
  • Posts: 226
Re: how can i select all items of Level?
« Reply #4 on: June 30, 2017, 09:12:36 pm »
majid.ebru,

you started this thread with an image of a treeview which has its root node location at the right side of the screen in stead of what one normally sees at the left.

how did you achieve this in lazarus?

frederic

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: how can i select all items of Level?
« Reply #5 on: June 30, 2017, 11:07:21 pm »
hi @frederic
see this topic
« Last Edit: June 30, 2017, 11:09:35 pm by majid.ebru »

 

TinyPortal © 2005-2018