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. Image for the cookie policy date

Binding a MultiColumnTreeView to a BindingList(Of Object).

How can you bind a MultiColumnTreeView to a BindingList(Of Object)? vb.net please.

Thank you,

8 Replies

KR Kannan R Syncfusion Team March 6, 2017 11:41 AM UTC

Hi Sam, 
 
Thank you for contacting Syncfusion support. 
 
Syncfusion MultiColumnTreeView control does not have Data Binding support and it is needed to populate Nodes in iteration process programmatically. Could you please share us more details about this requirement? So that we can analyze and provide prompt solution at the earliest.  
 
Regards 
Kannan 



MO Mohamad May 7, 2023 06:39 PM UTC

I have datatable , how to bind it to multiColumnTreeView, what I have is Accounts table and I have parents and child with multi-levels like:

AccName AccCode

-AccAna - Level1 1

--AccMohanna - Level2 11

---AccNader - Level3 111

the columns that I have (AccName - AccCode)

so how to populate the treeview to achieve that?



DM Dhanasekar Mohanraj Syncfusion Team May 10, 2023 01:39 PM UTC

Mohamad,

Your requirement to “Populating the data table to the MultiColumnTreeview” will be achievable by iterating the nodes and adding it programmatically as shown below,

this.Load += OnLoad;

private void OnLoad(object sender, EventArgs e)

{

    // Add columns to the MultiColumnTreeView

    TreeColumnAdv countryColumn = new TreeColumnAdv();

    TreeColumnAdv capitalColumn = new TreeColumnAdv();

 

    countryColumn.Text = "Country";

    capitalColumn.Text = "Capital";

 

    countryColumn.Width = 150;

    capitalColumn.Width = 150;

 

    multiColumnTreeView1.Columns.AddRange(new TreeColumnAdv[] { countryColumn, capitalColumn });

    // Add rows to the MultiColumnTreeView

    foreach(DataRow row in dataTable1.Rows)

    {

        multiColumnTreeView1.Nodes.Add(row["Name"].ToString());

        for(int i=0;i< multiColumnTreeView1.Nodes.Count;i++)

        {

            //  Add child nodes to the MultiColumnTreeView

            if (multiColumnTreeView1.Nodes[i].Text == row["Name"].ToString())

            {

                multiColumnTreeView1.Nodes[i].Nodes.Add(row["Capital"].ToString());

            }

        }           

    }

}


Here we have prepared the sample based on the above suggestion, please have a look at this.


Attachment: MultiColumnTreeviewDemo_71e89a4f.zip


MO Mohamad May 10, 2023 02:40 PM UTC

how to assign a value to the second column



DM Dhanasekar Mohanraj Syncfusion Team May 11, 2023 02:41 PM UTC

Mohamad,

You can populate the value for the second column by adding the TreeNodeAdvSubItem through the iterations shown below,

this.Load += OnLoad;

private void OnLoad(object sender, EventArgs e)

{

    // Add columns to the MultiColumnTreeView

    TreeColumnAdv countryColumn = new TreeColumnAdv();

    TreeColumnAdv capitalColumn = new TreeColumnAdv();

   

    countryColumn.Text = "Country";

    capitalColumn.Text = "Capital";

 

    countryColumn.Width = 150;

    capitalColumn.Width = 150;

 

    multiColumnTreeView1.Columns.AddRange(new TreeColumnAdv[] { countryColumn, capitalColumn });

    // Add rows to the MultiColumnTreeView

    foreach(DataRow row in dataTable1.Rows)

    {

        multiColumnTreeView1.Nodes.Add(row["Continent"].ToString());

        for(int i=0;i< multiColumnTreeView1.Nodes.Count;i++)

        {

            //  Add child nodes to the MultiColumnTreeView

            if (multiColumnTreeView1.Nodes[i].Text == row["Continent"].ToString())

            {

                multiColumnTreeView1.Nodes[i].Nodes.Add(row["Country"].ToString());

                {

                    // Add subitems to the MultiColumnTreeView

                    for(int j=0;j< multiColumnTreeView1.Nodes[i].Nodes.Count;j++)

                    {

                        treeNodeAdvSubItem = new TreeNodeAdvSubItem();

                        treeNodeAdvSubItem.Text = row["Capital"].ToString();

                        multiColumnTreeView1.Nodes[i].Nodes[j].SubItems.Add(treeNodeAdvSubItem);

                    }

                }

              

            }

        }           

    }

    this.multiColumnTreeView1.ExpandAll();

}


Here we have modified the sample based on the above suggestion, please have a look at this. Also, here we have attached the sample MultiColumnTreeview bound with the ObservableCollection for your reference. For more information related to DataBinding, please refer to the below user guide documentation link,

UG Link:
https://help.syncfusion.com/windowsforms/multicolumn-treeview/getting-started,
https://help.syncfusion.com/windowsforms/multicolumn-treeview/data-binding

With these references, you can populate the MultiColumnTreeview as your own depending on your requirement.


Attachment: Samples_49b8cb69.zip


MO Mohamad May 15, 2023 09:59 PM UTC

I'm using the folowing code to fill the nodes in (TreeViewAdv) :


xDv1.RowFilter = ""; xDv1.RowFilter = "AccType = 'رئيسي' AND AccParent > 0"; xDv1.Sort = "AccLevel"; foreach (System.Data.DataRow xDr in xDv1.ToTable().Rows) { TreeNode[] xFind = Tv.Nodes.Find(xDr["AccParent"].ToString(), true); Tv.SelectedNode = xFind[0]; Tv.SelectedNode.Nodes.Add(xDr["AccRef"].ToString(), xDr["xAccName"].ToString(), 1, 1); }

how to apply the same code in multicolumntreeview? I want to fill the treeview with unlimited levels



MO Mohamad May 16, 2023 12:22 AM UTC

and how to make a loop on all nodes with all children for all levels, and I want to get the value of a column for the selected node?



DM Dhanasekar Mohanraj Syncfusion Team May 16, 2023 03:08 PM UTC

Mohamad,

Please find the response to your queries below,

Query

Response

 

how to apply the same code in multicolumntreeview? I want to fill the treeview with unlimited levels.

and how to make a loop on all nodes with all children for all levels

 

 

We regret to let you know that Our MultiColumntreeView does not contain the support to bind the data source like our TreeViewAdv. For that, only we have shared the demo by populating nodes through iterations. With that reference, you can iterate the nodes and add the child nodes depending on their count. There, is no direct support for populating the data like TreeViewAdv.
 

 

I want to get the value of a column for the selected node?

 

 

 

You can get the selected node value by using the below code snippet,

 

this.multiColumnTreeView1.AfterSelect += MultiColumnTreeViewAfterSelect;

private
void MultiColumnTreeViewAfterSelect(object sender, EventArgs e)

{

    string selectedNode = (this.multiColumnTreeView1.SelectedNode as Syncfusion.Windows.Forms.Tools.MultiColumnTreeView.TreeNodeAdv).Text;

}





Loader.
Live Chat Icon For mobile
Up arrow icon