Recent

Author Topic: how can i select item in runtime ?  (Read 4573 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
how can i select item in runtime ?
« on: June 24, 2017, 08:02:55 pm »
Hi
.
i have a treeview.
.
how can i select a special item for example "M3" or "B2" or "A1" , in runtime?!?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how can i select item in runtime ?
« Reply #1 on: June 24, 2017, 10:41:00 pm »
Try this one for size.
Code: Pascal  [Select][+][-]
  1. procedure SelectNodeByText(const aTreeView:TTreeView; aNodeText:String);
  2. var
  3.   vNode : TTreeNode;
  4.   vLastNode : TTreeNode;
  5. begin
  6.   for vNode in aTreeView.Items do begin
  7.     if vNode.Text = aNodeText then begin
  8.       vLastNode := vNode;
  9.       vNode.Selected := True;
  10.       if not aTreeView.MultiSelect then Break;
  11.     end;
  12.   end;
  13.   vLastNode.Focused := True;
  14. end;
  15.  
No cpu suffered through the compilation of the above code and no compiler was harmed in the process of making it.
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

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: how can i select item in runtime ?
« Reply #2 on: June 27, 2017, 01:19:52 am »
Try this one for size.
Code: Pascal  [Select][+][-]
  1. procedure SelectNodeByText(const aTreeView:TTreeView; aNodeText:String);
  2. var
  3.   vNode : TTreeNode;
  4.   vLastNode : TTreeNode;
  5. begin
  6.   for vNode in aTreeView.Items do begin
  7.     if vNode.Text = aNodeText then begin
  8.       vLastNode := vNode;
  9.       vNode.Selected := True;
  10.       if not aTreeView.MultiSelect then Break;
  11.     end;
  12.   end;
  13.   vLastNode.Focused := True;
  14. end;
  15.  
No cpu suffered through the compilation of the above code and no compiler was harmed in the process of making it.

Hi
sorry for late.
.
this code doesn't work correctly?!?!
.
how can i directly select special item for example "M3" or "B2" or "A1" , in runtime?!?
.

??
« Last Edit: June 27, 2017, 01:54:40 am by majid.ebru »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: how can i select item in runtime ?
« Reply #3 on: June 27, 2017, 11:15:06 am »
Here's an example (not multiselect).

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: how can i select item in runtime ?
« Reply #4 on: June 27, 2017, 03:15:00 pm »
Here's an example (not multiselect).

thank you but what is this??
how can i use this code?
how can i directly select special item for example "M3" or "B2" or "A1" , in runtime?!? wihtout CLICK on item
« Last Edit: June 27, 2017, 03:18:04 pm by majid.ebru »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: how can i select item in runtime ?
« Reply #5 on: June 27, 2017, 04:56:14 pm »
thank you but what is this??

"this" is an example, based on your first post of treeview nodes with Text such as "A1" and "B2", of how to select a particular node at runtime, based on the node's text (entered via an edit control).
The example uses a procedure called SelectNode(), which takes a node text string as a parameter to  identify the node which should be selected.

To select items in a listview, as in your latest post, a similar sort of procedure could be devised, if at runtime you want to select a named item via code rather than through a user mouse click.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how can i select item in runtime ?
« Reply #6 on: June 27, 2017, 05:33:00 pm »
Try this one for size.
Code: Pascal  [Select][+][-]
  1. procedure SelectNodeByText(const aTreeView:TTreeView; aNodeText:String);
  2. var
  3.   vNode : TTreeNode;
  4.   vLastNode : TTreeNode;
  5. begin
  6.   for vNode in aTreeView.Items do begin
  7.     if vNode.Text = aNodeText then begin
  8.       vLastNode := vNode;
  9.       vNode.Selected := True;
  10.       if not aTreeView.MultiSelect then Break;
  11.     end;
  12.   end;
  13.   vLastNode.Focused := True;
  14. end;
  15.  
No cpu suffered through the compilation of the above code and no compiler was harmed in the process of making it.

Hi
sorry for late.
.
this code doesn't work correctly?!?!
.
how can i directly select special item for example "M3" or "B2" or "A1" , in runtime?!?
.

??
Not enough information. I have demonstrated everything you need to know to accomplish your task. If you do not understand something ask specific questions.
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

majid.ebru

  • Hero Member
  • *****
  • Posts: 502
Re: how can i select item in runtime ?
« Reply #7 on: June 29, 2017, 02:23:22 pm »
Ok
.
i put a buttom in form.


i want when i press button "M3" selected?
or
i want when i press button "B2" selected?
or
i want when i press button "A1" selected?
.
.
also in my program i don't know which item should selected and i have just text of item?


image post 1
« Last Edit: June 29, 2017, 02:25:29 pm by majid.ebru »

 

TinyPortal © 2005-2018