4

I have 5 nodes in my VirtualStringTree:

tree

Node #4 has no caption and should be skipped when the user presses VK_DOWN or VK_UP.

It should also not get selected when the user clicks on it.

I wrote this code (that works) to skip said node when using the keyboard:

if Key = VK_DOWN then
begin
  node := VirtualTree.GetNext(VirtualTree.FocusedNode);
  if not Assigned(node) then Exit;

  data := VirtualTree.GetNodeData(node);
  if data^.Caption = '' then
  begin
    VirtualTree.GetNext(node);
    VirtualTree.FocusedNode := node;
    VirtualTree.Selected[node] := true;
  end;
end
else if Key = VK_UP then
begin
  node := VirtualTree.GetPrevious(VirtualTree.FocusedNode);
  if not Assigned(node) then Exit;

  data := VirtualTree.GetNodeData(node);
  if data^.Caption = '' then
  begin
    VirtualTree.GetPrevious(node);
    VirtualTree.FocusedNode := node;
    VirtualTree.Selected[node] := true;
  end;
end;

The problem is that the node still gets focused by clicking on it.

I tried disabling the node VirtualTree.IsDisabled[node] := true; - but no luck.

Anyone knows a way to accomplish this?

ChrisB
  • 2,497
  • 2
  • 24
  • 43

1 Answers1

4

Handle the OnFocusChanging event and return False to the Allowed parameter for the node of your choice.

TLama
  • 75,147
  • 17
  • 214
  • 392
  • I somehow missed that event. Thanks :-) – ChrisB Dec 04 '14 at 21:58
  • 4
    You're welcome! Anyway, better handle the `OnKeyAction` event for your keyboard processing. Also, search for the nearest non-empty node by the `GetPreviousVisible` and `GetNextVisible` methods. And don't forget that there's more keys to handle, at least e.g. `VK_HOME` and `VK_END` in your case (do note that `OnFocusChanging` will prevent nodes to be focused by keyboard as well and so you'll need to find the nearest focusable node for all *navigation* keys, otherwise the keys won't do effectively nothing). – TLama Dec 04 '14 at 22:17