When using the mouse this code works perfectly:
procedure TForm1.vstPropertiesFocusChanged(Sender: TBaseVirtualTree; Node:
PVirtualNode; Column: TColumnIndex);
begin
if Assigned(Node) and (Sender.UpdateCount = 0) then
begin
if Column = 0 then
sender.FocusedColumn:=1;
vstProperties.EditNode(vstProperties.focusedNode, 1);
// Timer1.enabled:=true;
end;
end;
However when using the keyboard after the focusChanged is this will end the editing for the freshly selected node:
VirtualTrees.BaseTree.TBaseVirtualTree.EndEditNode
VirtualTrees.BaseTree.TBaseVirtualTree.DoFocusNode($3455090,True)
VirtualTrees.BaseTree.TBaseVirtualTree.SetFocusedNode($3455090)
VirtualTrees.BaseTree.TBaseVirtualTree.AddToSelection($3455090,False)
VirtualTrees.BaseTree.TBaseVirtualTree.WMKeyDown((256, (), 40, 0, (), 22020097, (), 0))
For me a small change in the TBaseVirtualTree.AddToSelection solved the problem. Do not change the FocusedNode if it is already equals to node. (The if that is bolded)
procedure TBaseVirtualTree.AddToSelection(Node: PVirtualNode; NotifySynced: Boolean);
var
Changed: Boolean;
RemoveSyncAfterChange: Boolean;
begin
if not FSelectionLocked then
begin
Assert(Assigned(Node), 'Node must not be nil!');
Changed := InternalAddToSelection(Node, False);
if Changed then
begin
UpdateNextNodeToSelect(Node);
if (SelectedCount = 1) then
begin
if FocusedNode <> Node then
FocusedNode := Node; // if only one node is selected, make sure the focused node changes with the selected node
end;
InvalidateNode(Node);
RemoveSyncAfterChange := NotifySynced and not (tsSynchMode in fStates);
if RemoveSyncAfterChange then
Include(FStates, tsSynchMode);
try
Change(Node);
finally
if RemoveSyncAfterChange then
Exclude(FStates, tsSynchMode);
end;
end;
end;
end;
When using the mouse this code works perfectly:
procedure TForm1.vstPropertiesFocusChanged(Sender: TBaseVirtualTree; Node:
PVirtualNode; Column: TColumnIndex);
begin
if Assigned(Node) and (Sender.UpdateCount = 0) then
begin
if Column = 0 then
sender.FocusedColumn:=1;
// Timer1.enabled:=true;
end;
end;
However when using the keyboard after the focusChanged is this will end the editing for the freshly selected node:
VirtualTrees.BaseTree.TBaseVirtualTree.EndEditNode
VirtualTrees.BaseTree.TBaseVirtualTree.DoFocusNode($3455090,True)
VirtualTrees.BaseTree.TBaseVirtualTree.SetFocusedNode($3455090)
VirtualTrees.BaseTree.TBaseVirtualTree.AddToSelection($3455090,False)
VirtualTrees.BaseTree.TBaseVirtualTree.WMKeyDown((256, (), 40, 0, (), 22020097, (), 0))
For me a small change in the TBaseVirtualTree.AddToSelection solved the problem. Do not change the FocusedNode if it is already equals to node. (The if that is bolded)
procedure TBaseVirtualTree.AddToSelection(Node: PVirtualNode; NotifySynced: Boolean);
var
Changed: Boolean;
RemoveSyncAfterChange: Boolean;
begin
if not FSelectionLocked then
begin
Assert(Assigned(Node), 'Node must not be nil!');
Changed := InternalAddToSelection(Node, False);
if Changed then
begin
UpdateNextNodeToSelect(Node);
if (SelectedCount = 1) then
begin
if FocusedNode <> Node then
FocusedNode := Node; // if only one node is selected, make sure the focused node changes with the selected node
end;
InvalidateNode(Node);
RemoveSyncAfterChange := NotifySynced and not (tsSynchMode in fStates);
if RemoveSyncAfterChange then
Include(FStates, tsSynchMode);
try
Change(Node);
finally
if RemoveSyncAfterChange then
Exclude(FStates, tsSynchMode);
end;
end;
end;
end;