Click here to Skip to main content
15,893,663 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..

I am using windowApplication.I dont have any idea about treeview control.I have to bind data in treeview from database.I have a table in database as "OrderDetails".In that i have two column like BillNo and OrderNo.so I have to show BillNo as parentnode
and orderno as childnode.Like this;
+BillNO
-OrderNo1
-OrderNo2.
how would i do this please sumbody help me..

Thanks.
Posted

1 solution

Check this logic it might helps u.

C#
dsModules = bfOnlyMasterPage.GetModuleTreeViewList(cmnOnlyMasterPage);// Get dataset from database.

DataTable dt=dsModules.Tables[0];
foreach (DataRow masterRow1 in dt.Rows)
{
      TreeNode masterNode1 = new TreeNode((string)masterRow1["BillNO"], Convert.ToString(masterRow1["BillNO"]));
      trView.Nodes.Add(masterNode1);
      foreach (TreeNode tn in trView.Nodes)
      {
           DataRow[] drlevels = dsModules.Tables[0].Select("BillNO=" + tn.Value);
           int i = 0;
           foreach (DataRow drlevel in drlevels)
           {
               tn.ChildNodes.Add(new TreeNode(drlevel["OrderNo1 "].ToString(), drlevel["OrderNo1 "].ToString()));
               i++;
           }
     }

}
 
Share this answer
 
v2
Comments
Shivani Dash 17-Dec-12 0:39am    
if i'll use datatable instead of dataset will it b ok?
Sanjeev Alamuri 17-Dec-12 1:00am    
dataset contains datatables. so u can extract datatable from datasets.
datatabel=dsModules.Tables[0];//0 means index.

U can replace top foreach loop as fallows.

foreach (DataRow masterRow1 in dtTables.Rows)
{
.
see my updated answer above.
Shivani Dash 17-Dec-12 1:22am    
dsModules = bfOnlyMasterPage.GetModuleTreeViewList(cmnOnlyMasterPage);
what is ds?
Sanjeev Alamuri 17-Dec-12 1:28am    
the first line is to get dataset from database using 3-tier architecture. u need not bother about this. here dsModule is dataset.
its the code in my project. there is nothing about ds. u have a datatable. so can move from foreach statement.
Shivani Dash 17-Dec-12 1:31am    
ya but it shows error lines in
TreeNode masterNode1 = new TreeNode((string)masterRow1["BillNO"], Convert.ToString(masterRow1["BillNO"]));
its shows "invalid argument"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900