We help IT Professionals succeed at work.

How to 'unfocus' a node?

patelkalp_a
patelkalp_a asked
on
1,362 Views
Last Modified: 2013-11-23
I have a fully functional tree, all is well in that regard.  One question though, if a user clicks on a blank area of the tree how do I remove the focus from the last node they clicked on?  I Thought enabling ExtendedFocus was the way to go, but despite the node highlighting being removed, it still retains focus.

Kind Regards
Richard
Comment
Watch Question

CERTIFIED EXPERT

Commented:
I think what you are looking for is under PaintOptions->toHideSelection=True
CERTIFIED EXPERT

Commented:
Or perhaps it's vTree.ClearSelection.
I am still trying to figure out how to know you've clicked on a blank part of the tree.
developmentguruPresident

Commented:
This code does it for me, let me know if you have any questions.
procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Node : TTreeNode;
  R : TRect;
 
begin
  Node := TreeView1.GetNodeAt(X, Y);
  if Assigned(Node) then
    begin
      R := Node.DisplayRect(true);
      if not PtInRect(R, Point(X, Y)) then
        Node := nil; //If it is on the line but not in the text rect...
    end;
  if not Assigned(Node) then
    TreeView1.Selected := nil;
end;

Open in new window

CERTIFIED EXPERT

Commented:
developmentguru,
Based upon the tags that patelkalp_a put on the Q I assume that he is using a TVirtualStringTree. Is this not true patelkalp_a?

Author

Commented:
Yes, it's virtualtreeview...I have a feeling both solutions will work - one is pre-processing, one is post-processing.  Checking now...

Author

Commented:
I wish I could edit my last comment.  Apparently there's no DisplayRect in virtualtreeview - hard to believe there's anything *not* included in this component though.  I half expect to stumble on a VirtualStringTree1.ShowWhereJimmyHoffaIsBuried function one of these days...
The clearselection does work if I put it at the end of the VirtualStringTree1Click event, but the user being unable to see the last item clicked could get problematic.
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Nice find...thanks for your help :)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.