Copy selected element from RadTreeView to RadListBox

6 posts, 0 answers
  1. Colince
    Colince avatar
    11 posts
    Member since:
    Apr 2013

    Posted 14 Jun 2013 Link to this post


    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>

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Jun 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Colince
    Colince avatar
    11 posts
    Member since:
    Apr 2013

    Posted 17 Jun 2013 Link to this post

    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?
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Jun 2013 Link to this post

    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.
  6. Colince
    Colince avatar
    11 posts
    Member since:
    Apr 2013

    Posted 18 Jun 2013 Link to this post

    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.

      
  7. Colince
    Colince avatar
    11 posts
    Member since:
    Apr 2013

    Posted 18 Jun 2013 Link to this post

    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);
                }
            }
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017