Get node path

There is an angular example of how to return the fullpath for a node.  I need to do this with Xamarin.Forms.  I have tried to convert angular to c# but I failed miserably.  I cannot make it work.  Can someone point me to a solution that shows how to return the path of a node/element within a node?


Brian



6 Replies

SV Suja Venkatesan Syncfusion Team January 6, 2022 01:20 PM UTC

Hi Brian, 

You can achieve your requirement by SfTreeview ItemTapped event which has the tapped item as its arguments and get the full path of that node by concatenating node name upto root parent node level as like below code snippet. 

Code snippet: 
private void SfTreeView_ItemTapped(object sender, Syncfusion.XForms.TreeView.ItemTappedEventArgs e) 
        { 
            string nodepath = viewModels.GetNodePath(e.Node); 
            App.Current.MainPage.DisplayAlert("Path ", nodepath, "Ok"); 
        } 
 
       public string GetNodePath(Syncfusion.TreeView.Engine.TreeViewNode node) 
        { 
            string fullpath = ""; 
            string path = ""; 
            while (node != null) 
            { 
                path = @"\" + (node.Content as FileManager).ItemName; 
                if (node.ParentNode != null) 
                { 
                    node = node.ParentNode; 
                } 
                else 
                { 
                    node = null; 
                } 
                fullpath = path + fullpath; 
            } 
            return fullpath; 
        } 

We have prepared a simple sample based on your requirement and attached it in below sample for you reference.  

Please have look at this sample and let us know if you have any concern. 

Regards, 
Suja 



BR Brian January 6, 2022 07:42 PM UTC

This is beautiful.  Thank you.  Now I need to integrate lazy loading to pull data from a REST API. 



LN Lakshmi Natarajan Syncfusion Team January 7, 2022 01:06 PM UTC

Hi Brian, 
 
We are glad that our solution meets your requirement. Please let us know if you need further assistance. As always, we are happy to help you out. 
 
Lakshmi Natarajan 
 



BR Brian January 7, 2022 11:44 PM UTC

Sorry to trouble again.  I used the example above.  I am using the NodeExpanding event in the behaviors code.  When I try to add said data it never populates in the node.  What on earth am I doing wrong?  I've added the event code here. the code below is located in SFTVBehaviors.cs


        private void sfTreeview_NodeExpanding(object sender, NodeExpandingCollapsingEventArgs e)

        {

            var nodeImageInfo = new ObservableCollection<FileManager>();

            Assembly assembly = typeof(ItemsPage).GetTypeInfo().Assembly;

            var tvnc = new ObservableCollection<TreeViewNode>();

            var tvn = new TreeViewNode();

            var node = e.Node;

            node.ChildNodes.Clear();

            var path = GetNodePath(node);


            var ph = new FileManager() { ItemName = "Placeholder", ImageIcon = ImageSource.FromResource("asbuiltgui_mobile.Icons.treeview_folder.png", assembly) };

            var placeholder = new ObservableCollection<FileManager>();

            placeholder.Add(ph);


            var results = Utils.UtilityCalls.lambdaGetFolders(path);

            var folders = JsonConvert.DeserializeObject<List<string>>(results);




            foreach (string Folder in folders)

            {

                tvn.Content = new FileManager() { ItemName = Folder, ImageIcon = ImageSource.FromResource("asbuiltgui_mobile.Icons.treeview_folder.png", assembly), SubFiles = placeholder };

                tvnc.Add(tvn);

            }



            node.PopulateChildNodes(tvnc);


            if (node.ChildNodes.Count() > 0)

                //Expand the node after child items are added.

                node.IsExpanded = true;


        }







BR Brian January 10, 2022 01:55 AM UTC

Sorry you can ignore the previous request.  I was able to fix it with lazy loading.  Now the last issue Im having is I cannot get vertical or horizontal scrolling to work.  How do I diagnose that and fix it?



LN Lakshmi Natarajan Syncfusion Team January 10, 2022 11:57 AM UTC

Hi Brian, 
 
When loading more items than the screen size, the SfTreeView allows for vertical scrolling. Please refer to our user guidance document regarding scrolling in SfTreeView from the following link, 
 
 
For horizontal scrolling, we have logged a feature request for the same. As of now plan for implementation of reported feature request is uncertain. 
  
  
We will prioritize the features every release based on the demands and we do not have an immediate plan to implement this feature since we committed with already planned work. Please upvote this feature to make this our priority. If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal and cast your vote to make it count.  
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon