Hi
Please advise how i can clone a tree view
I have a radDropDownList and a RadTreeView.
upon selection in the drop down, my data chages, though the table structure remain the same. Suppose i have options 1 and 2 in the drop down. user selects option 1 and tree is populated. User makes some selections in tree check boxes, then select option 2 from drop down list, new data populateed in tree view, and user does further selections in tree view. Now user goes back to option 1, i should get the tree view with data and tick selections
below are my codes, but this does not seem to be good. tvNode is in designer
local variables
RadTreeView tvAsset = new RadTreeView();
RadTreeView tvDriver = new RadTreeView();
private void cbStruc_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (cbStruc.SelectedItem == null)
return;
int i = 0;
Image imagetemp;
switch (cbStruc.SelectedItem.ToString())
{
case "Assets":
if (tvAsset.Nodes.Count == 0)
{
TreeView tv = new TreeView();
new GroupMatrix().PopulateTreeCategories(tv, Globals.uLogin.lMatrix, cbStruc.SelectedItem.ToString());
tvNode.ClearSelection();
tvNode.DataSource = Globals.dtGMTreeCategory;
tvAsset = CloneTreeNodes(tvNode);
}
else
{
tvNode.ClearSelection();
tvNode = CloneTreeNodes(tvAsset);
}
break;
case "Drivers":
if (tvDriver.Nodes.Count == 0)
{
TreeView tv = new TreeView();
new GroupMatrix().PopulateTreeCategories(tv, Globals.uLogin.lMatrix, cbStruc.SelectedItem.ToString());
tvNode.ClearSelection();
tvNode.DataSource = Globals.dtGMTreeCategory;
tvDriver = CloneTreeNodes(tvNode);
}
else
tvNode = CloneTreeNodes(tvDriver);
break;
}
tvNode.ExpandAll();
}
private void cbStruc_SelectedIndexChanging(object sender, Telerik.WinControls.UI.Data.PositionChangingCancelEventArgs e)
{
if (cbStruc.SelectedItem != null)
switch (cbStruc.SelectedItem.ToString())
{
case "Assets":
tvAsset = CloneTreeNodes(tvNode);
break;
case "Drivers":
tvDriver = CloneTreeNodes(tvNode);
break;
}
}
RadTreeView CloneTreeNodes(RadTreeView tvFrom)
{
RadTreeView treeview2 = new RadTreeView();
if (tvFrom.Nodes.Count == 0)
return treeview2;
foreach (RadTreeNode tn in tvFrom.Nodes)
treeview2.Nodes.Add((RadTreeNode)tn.Clone());
treeview2.DataSource = tvFrom.DataSource;
return treeview2;
}
Kindly advise
Thank you