TAdvTreeView - Single checked radio button

I have a treeview with radio buttons on level 2 nodes. The default behaviour seems to be that one radio button is checked for each set of nodes with the same parent. I would like to have only one radio button checked over the entire tree.

Is there currently a setting to do this, or will I need to attach code to the OnAfterCheckNode event to uncheck all the other radio buttons.

If the latter, what is the fastest way to traverse all the nodes - currently I've just written a simple recursive procedure similar to the code below:

procedure TForm9.AdvTreeView1AfterCheckNode(Sender: TObject; ANode: TAdvTreeViewVirtualNode; AColumn: Integer);
   procedure Uncheck(Nodes:TAdvTreeviewNodes);
   var N:integer;
   begin
     for N := 0 to Nodes.Count-1 do
     begin
       if Nodes[N]<>ANode.Node then Nodes[N].Checked[0]:=FALSE;
       Uncheck(Nodes[N].Nodes);
     end;
   end;
begin
  Uncheck(AdvTreeview1.Nodes);
end;

Thanks in advance for your advice.


Hi, 


This is indeed the default behavior, only one radiobutton can be checked per parent.
There is no separate setting to control this behavior. The current code you have implemented is correct and can be used to manually uncheck other nodes.

We will investigate if we can improve this behavior.

Kind Regards, 
Pieter

Thank you!

One further question... I seems that the default radio button behaviour only works with collection based nodes, rather than virtual nodes.
If I'm correct, for virtual nodes I need to implement IsOnNodeChecked method and set AChecked accordingly.
If I maintain the checked status of nodes in my own data, and use this to set the AChecked value, is there a way of knowing when the user has clicked the radio button to enable me to update my own data? (OnNodeClick only fires if you click the text, but not the radio button)

At the moment I'm just experimenting with this new component, and I'm not sure if I'll need to implement radio buttons with virtual nodes, but if I do I'd like to know that it's possible.

Thanks again for your advice,

Hi, 


The event that is triggered is the OnAfterCheckNode event. There you can set the boolean property of your data to true. the OnAfterUnCheckNode event is for setting the value to false.
There is no need to refresh the treeview, the virtual node is also automatically checked. If an update occurs, the value is read again through the OnIsNodeChecked event.

Kind Regards, 
Pieter

Thank you. I hadnt noticed the OnAfterUnCheckNode method (as well as OnAfterCheckNode)