BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
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?
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; { // 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.
how to assign a value to the second column
Mohamad,
You can populate the value for the second column by adding the TreeNodeAdvSubItem through the iterations shown below,
this.Load += OnLoad; { // 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.
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
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?
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,
|