Hello,
I tried quite a few things trying to bind an object to the Treeview but it does not seem to work.
I have two readlonly list based objects which I retrieve and form a Parent-Child relationship in the UI using the object adapters and datasets.I want to bind this dataset to the treeviw but I guess its wrong.My application is an ASP.net application. An example would be of great help.
Root Node -- > Repair Category
ParentNode-->RepairGroup
ChildNode-->RepairSubGroup
ChildNode-->RepairSubGroup
Thanks
V
I was able to do it using tree nodes .Sorry for wasting your precious time.Just in case Newbies like me want to bind data to the tree view here is the code.if there is better ways to implement this I would be glad to know and if its not the right way please advice.
DataSet ds = new DataSet();
RepairGroupList repairGroupList = RepairGroupList.GetRepairGroupList();
RepairSubGroupList repairSubGroupList = RepairSubGroupList.GetRepairSubGroupList();
ObjectAdapter repairGroupListAdp = new ObjectAdapter();
ObjectAdapter repairSubGroupListAdp = new ObjectAdapter();
repairGroupListAdp.Fill(ds, "RepairGroup", repairGroupList);
repairSubGroupListAdp.Fill(ds, "RepairSubGroup", repairSubGroupList);
if (ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow row in ds.Tables[0].Rows)
{
TreeNode newNode = new TreeNode();
newNode.Text = row["RepairGroupName"].ToString();
newNode.Value = row["RepairGroupName"].ToString();
newNode.PopulateOnDemand = true;
newNode.SelectAction = TreeNodeSelectAction.Expand;
tvRepairGroup.Nodes.Add(newNode);
foreach( DataRow childRow in ds.Tables[1].Rows)
{
if(row["RepairGroupID"].ToString() == childRow["RepairSubGroupID"].ToString())
{
TreeNode newChildNode = new TreeNode();
newChildNode.Text = childRow["RepairSubGroupName"].ToString();
newChildNode.Value = childRow["RepairSubGroupName"].ToString();
newNode.ChildNodes.Add(newChildNode);
}
}
}
}
Copyright (c) Marimer LLC