Recent

Author Topic: [solved] Deselect items in treeview?  (Read 3868 times)

piola

  • Full Member
  • ***
  • Posts: 118
  • Lazarus 2.2, 64bit on Windows 8.1 x64
[solved] Deselect items in treeview?
« on: January 20, 2019, 10:23:14 am »
Hello,

I'm using a TTreeView component with MultiSelect=TRUE and MultiSelectStyle=[msControlSelect, msShiftSelect, msVisibleOnly].

I would appreciate if someone tells me how I can deselect a selected item. My intuitive approach was to set TreeView.Items[n].Selected := FALSE, but this does nothing. I have been looking for a remove or delete method of the TreeView.Selections, but there doesn't seem to be one.

In contrast to Delphi, there seems to be no TreeView.Delete method either.

So what it is the prefered way of deselecting a TreeView node?

Thanks for any help!
« Last Edit: January 20, 2019, 04:41:01 pm by piola »

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Deselect items in treeview?
« Reply #1 on: January 20, 2019, 12:48:33 pm »
There is method ClearSelection();.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

piola

  • Full Member
  • ***
  • Posts: 118
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Deselect items in treeview?
« Reply #2 on: January 20, 2019, 01:20:51 pm »
Yes, thanks, but this removes the selection of all nodes. I want to deselect only some nodes.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Deselect items in treeview?
« Reply #3 on: January 20, 2019, 02:35:29 pm »
This works (I looked how is ClearSelection implemented):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var ANode, OldNode: TTreeNode;
  3. begin
  4.   ANode := TreeView1.GetFirstMultiSelected;
  5.   while assigned(ANode) do
  6.     begin
  7.       OldNode := ANode;
  8.       ANode := ANode.GetNextMultiSelected;
  9.       if OldNode.Text[1] = 'G' then OldNode.MultiSelected := false;
  10.     end;
  11.   if TreeView1.Selected.Text[1] = 'G' then TreeView1.Selected:=nil;
  12. end;
This deselects all nodes beginning with 'G'.
Note: (Main) selected node and the other mutliselected nodes are handled separately, therefore, you need to apply condition separately too.

Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

piola

  • Full Member
  • ***
  • Posts: 118
  • Lazarus 2.2, 64bit on Windows 8.1 x64
Re: Deselect items in treeview?
« Reply #4 on: January 20, 2019, 04:40:43 pm »
Great! Thank you very much!  :)

 

TinyPortal © 2005-2018