TTMSFMXTreeView: Problem with multiselection of nodes at runtime in code

If I select a node in code, all nodes are deselected (FSelectedNodes.Clear;) before the node will be selected. How can I select a node without deselecting the currently selected nodes?

For a quick solution I patched the unit FMX.TMSCustomTreeView:

procedure TTMSFMXCustomTreeView.SelectVirtualNode(ANode: TTMSFMXTreeViewVirtualNode);
var
en: Boolean;
begin
// nol- FSelectedNodes.Clear;
if Assigned(ANode) then
begin
en := IsVirtualNodeSelectable(ANode);
if en then
begin
FSelectedNodes.Add(ANode);
FFocusedNode := ANode;
end;
end;
Repaint;
end;

To select multiple nodes, please use:

TMSFMXTreeView1.SelectNodes(Array);

instead

Thanks for your answer. I don't want to select multiple nodes at once. How can I select a single node without deselection of currently selected nodes?

I'm not sure exactly what you want to achieve. You either want to select a single node, or multiple nodes. If you want to select one node, you just give an array of one item in the SelectNodes call. If you want to select another node, you need to include the original node. There is no alternative for this.

I want to add a node to the currently selected nodes list.

If I use your suggestion to use TMSFMXTreeView1.SelectNodes(Array), how can I access the Array of the currently selected nodes? Then I could TMSFMXTreeView1.SelectNodes(CurrentSelectedNodesArray + NodeToSelect)

You can access the Selected nodes array with:

TMSFMXTreeView1.SelectedNodes[Index: Integer]

and the count with

TMSFMXTreeView1.SelectedNodeCount

You can then construct the array by looping through the selected nodes.

It would be nice and logical to have a

procedure AddNodeToSelection(ANode: TTMSFMXTreeViewVirtualNode); override;
(this would be the counterpart to RemoveNodeFromSelection)

Hi,

We have added this method, next version will have this included.
Thanks for the feedback!