We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to load TreeNavigator from DB

Thread ID:

Created:

Updated:

Platform:

Replies:

144296 Apr 29,2019 03:35 PM UTC May 1,2019 12:06 PM UTC WinForms 5
loading
Tags: TreeNavigator
Martin
Asked On April 29, 2019 03:35 PM UTC

I am trying to load the TreeNavigator from a database based on user permissions. The list could be 3-4 child deep with some not having any children. I am trying to achieve this is VB.net.

Thanks, Martin

Sabaridass Ramamoorthy [Syncfusion]
Replied On April 30, 2019 08:50 AM UTC

Hi Martin, 
 
Thanks for contacting Syncfusion Support. 
 
We have prepared a simple sample to achieve your requirement and it can be downloaded from below location. 
 
Kindly refer to the below code example which helps you to add child nodes based on your needs. 
#Form1.cs 
 
private void TreeNavigator1_SelectionChanged(TreeNavigator sender, SelectionStateChangedEventArgs e) 
        { 
            TreenavigatorItemsUpdate(treeNavigator1, e); 
        } 
        private void TreenavigatorItemsUpdate(TreeNavigator sender, SelectionStateChangedEventArgs e) 
        { 
            TreeNavigator tree = sender as TreeNavigator; 
            dataBaseView.Table.Rows.Cast<DataRow>().ToList().ForEach(x => 
               { 
                   if (dataBaseView.Table.Columns.Contains(e.SelectedItem.Text)) 
                       e.SelectedItem.Items.Add(new TreeMenuItem() { Text = x[dataBaseView.Table.Columns[e.SelectedItem.Text]].ToString() }); 
               }); 
            
        } 
 
If the above solution doesn’t meet your actual requirement, you can share some more detailed information about your requirement. So that we could provide the solution at the earliest. 
 
Regards, 
Sabaridass R 
 


Martin
Replied On April 30, 2019 09:40 AM UTC

Hi, Thanks for the example. Am i right in thinking that you only add the child items upon each click of the parent and not load them at the start? Also i am having an issue converting to VB, do you have any samples in VB?

Thanks, Martin

Sabaridass Ramamoorthy [Syncfusion]
Replied On April 30, 2019 10:41 AM UTC

Hi Martin, 
 
You can also add child nodes at the beginning while adding parent nodes. Kindly refer to the below code example. 
Private Sub FillItems(ByVal tree As TreeNavigator) 
                For Each col As DataColumn In dataBaseView.Table.Columns 
                           Me.treeNavigator1.Items.Add(New TreeMenuItem() With {.Text = col.ColumnName}) 
                Next col 
                     For Each x As DataRow In dataBaseView.Table.Rows 
                           For Each y As TreeMenuItem In Me.treeNavigator1.Items 
                                  If dataBaseView.Table.Columns.Contains(y.Text) Then 
                                         y.Items.Add(New TreeMenuItem() With {.Text = x(dataBaseView.Table.Columns(y.Text)).ToString()}) 
                                  End If 
 
                           Next y 
                     Next x 
              End Sub 
 
We have prepared a sample in VB with modified code changes and it can be downloaded from below location. 
 
Regards, 
Sabaridass R 


Martin
Replied On April 30, 2019 11:57 AM UTC

Thank you, i have successfully got the parent and child node working. But how would i go about adding a child to a child? I need to be able to go 5 childs deep.

Thanks, Martin

Jagadeesan Pichaimuthu [Syncfusion]
Replied On May 1, 2019 12:06 PM UTC

  
Hi Martin,

Thanks for the update.

In TreeNavigator there is no default support to bind items through Database and it can be achieved by loading TreeMenuItem in iteration process from DataTable. We have modified the sample as per your requirement and it can be downloaded from below location.

Sample: TreeNavigator_DataBinding 

In this sample we have initialized the DataTable with required data, integrated the DataTable in DataSet and created and loaded TreeMenuItem in TreeNavigator.
 

Please check the above sample and let us know if you require further assistance on this.

Regards,
 
Jagadeesan

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon