AddNodes is obsolete

18.3.0.44 - I am dynamically adding child nodes to a tree bound to a self-referential List. The only way of doing this is to call AddNodes, but it gives this warning:

Warning CS0618 'SfTreeView<TocNode>.AddNodes(List<TocNode>, string?)' is obsolete: 'This method is deprecated. You can use Fields.Datasource property to directly pushed the additional data in TreeView'

It has been explained in this forum previously that adding items to the datasource List does not affect the tree in the UI because the binding is one way. I have verified that is true, which contradicts the suggestion in the warning message.

So what is the correct way to dynamically add nodes to the tree?

Thanks, Greg

P.S. The grammar of the warning message should be corrected as well as making it more specific and helpful.

3 Replies 1 reply marked as answer

SP Sowmiya Padmanaban Syncfusion Team November 5, 2020 10:23 AM UTC

Hi  Greg Keogh,  
 
Greetings from Syncfusion support. 
 
TreeView has no two-way binding for the data source property in our previous versions(release version before 18.3.35). So, we suggested to use AddNodes method for adding nodes in TreeView dynamically. 
 
We have provided a two-way binding support for data source property from Syncfusion.Blazor NuGet version 18.3.35 as part of optimizing the functionalities  and performance of the component. So, there is no need to use AddNodes and RemoveNodes properties in TreeView. Due to this reason, we have deprecated the AddNodes/RemoveNodes method from release version 18.3.35. 
 
Now, when you directly update the data source to add/remove tree nodes in TreeView. This changes will automatically reflect in UI of TreeView component. 
 
Please, refer to the below release notes for breaking changes of TreeView component on the version 18.3.35. 
 
 
Please refer to the code snippet of the above explained solution. 
 
<SfButton Content="ADD_Node" OnClick="Add_Node"></SfButton> 
<SfButton Content="Remove_Node" OnClick="Remove_Node"></SfButton> 
<SfTreeView @ref="tree" TValue="MailItem"> 
    <TreeViewFieldsSettings TValue="MailItem" Id="Id" DataSource="@MyFolder" Text="FolderName" ParentID="ParentId" HasChildren="HasSubFolders" Expanded="Expanded"></TreeViewFieldsSettings> 
</SfTreeView> 
  public void Add_Node() 
    { 
        MyFolder.Add(new MailItem 
        { 
            Id = "7", 
            ParentId = "2", 
            FolderName = "Music" 
        }); 
    }    public void Remove_Node() 
    { 
       List<MailItem> removeNode = tree.GetTreeData("3"); 
        MyFolder.Remove(removeNode.ElementAt(0)); 
    } 
 
We have attached the sample with above solution for your reference. Please, download the samples from the following link. 
 
 
Refer to the below link to know more about the TreeView component. 
 
 
 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 


Marked as answer

UN Unknown November 5, 2020 09:07 PM UTC

Good grief! I was on version 34 which is one behind 35 where this change was introduced. I just updated and found that 47 is already available.

Introducing two-way binding with the data source is a significant improvement which simplifies client code. I am already gratefully stripping out deprecated code. Luckily this is a beta release project and it's easy for me to update the code.

This would have been a serious breaking change had you not left the old methods there and annotated them with [Obsolete]. The 18.3.35 release notes at the link you provided do not seem to mention anything about deprecations or data source binding changes. A clearer deprecation message would also have been helpful.

In any case, the introduction of two-way data source binding is a great improvement.

Thanks, Greg


SP Sowmiya Padmanaban Syncfusion Team November 6, 2020 01:59 PM UTC

Hi Greg Keogh,  
 
As mentioned in our previous update, we have provided a two-way binding support to the datasource property of TreeView component. So, we have marked the addNodes/removeNodes method as deprecated. 
 
But, we have not removed that methods ( addNodes/RemoveNodes) in our TreeView component. We will remove the deprecated methods from the component only after the consecutive four releases. 
 
Refer the below sample link for AddNodes method in latest version:  https://www.syncfusion.com/downloads/support/forum/159424/ze/AddNodes-1488617943.zip 
 
So, we suggest you to directly update the data source to add/remove tree nodes in TreeView instead of using AddNodes method as the new changes in data source will automatically reflect in UI of TreeView component. 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 

Loader.
Up arrow icon