EDIT: Answered. The TTreeView.HideSelection was set to TRUE, so you needed TTreeView.SetFocus() to reflect in the UI the current state of TTreeView.selectedNIIL. Thanks!

EDIT: Answered. The TTreeView.HideSelection was set to TRUE, so you needed TTreeView.SetFocus() to reflect in the UI the current state of TTreeView.selected<>NIIL. Thanks!



TTreeView.SetFocus() before TTreeView.TTreeNode.selected:=TRUE

After about an hour of trying to set the selected TTreeNode in a TTreeView, I started googling and found this (as well as other links) that indicate you must perform a TTreeView.SetFocus() in order to programatically set the selected TTreeNode.

It works, I plugged the code in and it's working great now.

However, I don't understand why?

Why do you need to SetFocus()? I don't believe you need to do it for a TListView. The only way I remember things, is if I remember the reason for it. Any ideas why? (beyond, "the control needs to have the focus", as that's obvious, but doesn't explain why)

PLATFORM: Delphi 10.2 on Win10 with VCL

Comments

  1. Cristian Peța Winner! This was indeed the answer, as the TTreeView was "HideSelection=TRUE'. Which makes sense on why ".SetFocus()" was effective. I'm glad I asked why, I hate magic. Thanks!!

    ReplyDelete
  2. Vin Colgin dig the suggestion by Fred Ahrens also work?

    ReplyDelete
  3. Jeroen Wiert Pluimers didnt try. Hideselection worked better for my code.

    ReplyDelete

Post a Comment