This is a migrated thread and some comments may be shown as answers.

Copy selected element from RadTreeView to RadListBox

5 Answers 120 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Colince
Top achievements
Rank 1
Colince asked on 14 Jun 2013, 02:17 PM

Hi!
 I'm using RadTreeView and RadListBox. I have an usual requierement considering the  scenario i have in the left side a RadTreeView incorporated inside the RadlistBox and in the right side i have the RadListBox. I have two issues :
1 - My issue is that how can i select one or more element on the RadTreeView and copy them inside the RadListBox?
2 - There's a way  to select a node with a relative child why the node is clicked?
Can you please give me some reply
Thanks

My jsp 
<td>
    <asp:Panel ID="pnlDealers" runat="server">
        <telerik:RadListBox ID="rlbDealer" runat="server" Height="200" Width="250" AllowTransfer="true"
                            ButtonSettings-Position="Right" ButtonSettings-TransferButtons="All"
                            TransferMode="Copy" SelectionMode="Multiple" TransferToID="rlbDealers"
                            AutoPostBackOnTransfer="true" CausesValidation="false">
            <ItemTemplate>
                <div>
                    <telerik:RadTreeView ID="rtvDealersAvailable" runat="server" OnLoad="rtvDealersAvailable_Load"
                                         OnNodeClick="rtvDealersAvailable_NodeClick">
                    </telerik:RadTreeView>
                </div>
            </ItemTemplate>
            <Items>
                <telerik:RadListBoxItem />
            </Items>
        </telerik:RadListBox>
        <telerik:RadListBox ID="rlbDealers" runat="server" SelectionMode="Multiple" Height="200" Width="250">
        </telerik:RadListBox>
    </asp:Panel>
</td>

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Jun 2013, 05:51 AM
Hi,
I suppose you need to copy the selected nodes to 'rlbDealers' listbox and also need to select the child nodes of selected parent node. So please try the following code snippet to achieve the scenario.
C#:
/*to transfer the selected nodes */
protected void rlbDealer_Transferring(object sender, Telerik.Web.UI.RadListBoxTransferringEventArgs e)
{
    ArrayList tbResults = new ArrayList();
    RadTreeView treevview =(RadTreeView)rlbDealer.Items[0].FindControl("rtvDealersAvailable");
    foreach (RadTreeNode node in treevview.GetAllNodes())
    {
        if (node.Selected)
            tbResults.Add(node.Text);
    }
    foreach (string listitem in tbResults)
    {
        RadListBoxItem item = new RadListBoxItem();
        item.Text = listitem;
        rlbDealers.Items.Add(item);
    }
}
 
/* to select the child nodes of selected node*/
protected void rtvDealersAvailable_NodeClick(object sender, RadTreeNodeEventArgs e)
{
    RadTreeView rtvDealersAvailable = (RadTreeView)sender;
    RadTreeNode node = rtvDealersAvailable.SelectedNode;
    if (node.HasControls() == true)
    {
        foreach (RadTreeNode node1 in node.GetAllNodes())
        {
            node1.Selected = true;
        }
          
    }
}

Hope this will help you.
Thanks,
Shinu.
0
Colince
Top achievements
Rank 1
answered on 17 Jun 2013, 11:14 AM
Hi Shinu!
thanks for your answer.
I've try your code but there's an issue that it's not possible to maintain highlight all the selected node(father and childs) and transfert them with one clik.
When i click on the father node only this is highlight and the child no.
do you have any suggestion?
0
Shinu
Top achievements
Rank 2
answered on 18 Jun 2013, 04:19 AM
Hi,

I suppose you need to highlight the parent on child node click.
C#:
protected void rtvDealersAvailable_NodeClick(object sender, RadTreeNodeEventArgs e)
{
    RadTreeView rtvDealersAvailable = (RadTreeView)sender;
    RadTreeNode node = rtvDealersAvailable.SelectedNode;
    if (node.HasControls() == true)
    {
        foreach (RadTreeNode node1 in node.GetAllNodes())
        {
            node1.Selected = true;
        }
    }
    if(node.Level!=0)
     node.ParentNode.Selected = true; // to highlight the parent of selected node.
}
Hope this will help you.
Thanks,
Shinu.
0
Colince
Top achievements
Rank 1
answered on 18 Jun 2013, 07:55 AM
Hi
perhaps i didn't explain me well. I need to copy both parent and childs node from rtvDealersAvailable to rlbDealers. But i want to select parent and child node with one click on the parent node and view all the selected node highlight. AS you can see in the attach picture only the parent node is highlight.

  
0
Colince
Top achievements
Rank 1
answered on 18 Jun 2013, 02:31 PM
Hi,
Problem-solved by using this javascript function

function selectFatherAndChildNodes(sender, eventArgs) {
            var node = eventArgs.get_node();
            var allnode = node.get_allNodes();
            var status = node.get_selected();
            for (var i = 0; i < allnode.length; i++) {
                allnode[i].set_selected(status);
            }
        }
Tags
TreeView
Asked by
Colince
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Colince
Top achievements
Rank 1
Share this question
or