Results 1 to 8 of 8

Thread: [CLOSED] Select node on Treepanel with right click...

  1. #1
    Member
    Join Date
    Feb 2008
    Location
    Phoenix, AZ, USA
    Posts
    26

    [CLOSED] Select node on Treepanel with right click...

    How can I make the a treepanel node become selected by right clicking as well as left clicking?
    Last edited by Daniil; Sep 13, 2010 at 10:36 PM. Reason: [CLOSED]

  2. #2
    Ext.NET - Support Team Daniil's Avatar
    Join Date
    Jun 2010
    Location
    Saint-Petersburg, Russia
    Posts
    27,586
    Hello!

    Please look at the example.
    There handling of 'contextmenu' is used to achieve this behavior.

    Example
    Code:
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
        <ext:ResourcePlaceHolder runat="server" />
    
        <script type="text/javascript">
            Ext.onReady(function () {
                TreePanel1.getRootNode().cascade(function (node) {
                    node.on('contextmenu', TreePanel1.getSelectionModel().onNodeClick);
                })
            });    
        </script>
    
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:TreePanel ID="TreePanel1" runat="server" Height="300">
            <Root>
                <ext:TreeNode Text="Composers" Expanded="true">
                    <Nodes>
                        <ext:TreeNode Text="Beethoven" Expanded="true">
                            <Nodes>
                                <ext:TreeNode Text="Concertos" Expanded="true">
                                    <Nodes>
                                        <ext:TreeNode Text="Concert 1" />
                                        <ext:TreeNode Text="Concert 2" />
                                    </Nodes>
                                </ext:TreeNode>
                            </Nodes>
                        </ext:TreeNode>
                    </Nodes>
                </ext:TreeNode>
            </Root>
        </ext:TreePanel>
        </form>
    </body>
    </html>
    Last edited by geoffrey.mcgill; Sep 13, 2010 at 9:45 PM. Reason: code revision
    Daniil
    Ext.NET, Inc.
    Support Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | Twitter | Jobs

  3. #3
    Member
    Join Date
    Feb 2008
    Location
    Phoenix, AZ, USA
    Posts
    26
    That didn't seem to work. Here is my code sample. I put your Ext.onReady code in the head of my page. The rest of the Treepanel is being built in code behind.

    Code:
                                <ext:TreePanel
                                    ID="TreePanel1"
                                    runat="server"
                                    Width="250"
                                    RootVisible="False" 
                                    Layout="Fit" 
                                    ContextMenuID="MenuContext"
                                    TrackMouseOver="true" 
                                    Border="false"
                                    Padding="10">
                                </ext:TreePanel>
    
                                <ext:Menu runat="server" ID="MenuContext">
                                    <Items>
                                        <ext:MenuItem runat="server" Text="Text">
                                            <Listeners>
                                                <Click Handler="alert(#{TreePanel1}.getSelectionModel().getSelectedNode().text);"/>
                                            </Listeners>
                                        </ext:MenuItem>
                                    </Items>
                                </ext:Menu>

  4. #4
    Ext.NET - Dev Team geoffrey.mcgill's Avatar
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    8,662
    Hi tjbishop,

    I just tested @Daniil code above and it appears to work correctly. Getting the selected node does return the .text value.
    Geoffrey McGill
    Ext.NET, Inc.
    Founder, and Dev Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | @extnet | Jobs

  5. #5
    Member
    Join Date
    Feb 2008
    Location
    Phoenix, AZ, USA
    Posts
    26
    Could I be adding my nodes wrong in the code behind? All other functionality seems to be working okay.

  6. #6
    Ext.NET - Dev Team geoffrey.mcgill's Avatar
    Join Date
    Jan 2008
    Location
    Canada
    Posts
    8,662
    Quote Originally Posted by tjbishop View Post
    Could I be adding my nodes wrong in the code behind?
    Yes, it is possible.
    Geoffrey McGill
    Ext.NET, Inc.
    Founder, and Dev Team

    Ext.NET Examples | Ext.NET API Docs | ExtJS API Docs | @extnet | Jobs

  7. #7
    Member
    Join Date
    Feb 2008
    Location
    Phoenix, AZ, USA
    Posts
    26
    Oh yeah, I am adding the nodes on Page_Load. Could it be an order of operations issue?

  8. #8
    Member
    Join Date
    Feb 2008
    Location
    Phoenix, AZ, USA
    Posts
    26
    It seems that it was an order of operations issue. I used X.AddScript to execute the javascript after I loaded my treepanel...

    Code:
                    
    X.AddScript("TreePanel1.getRootNode().cascade(function (node) {" + 
    "node.on('contextmenu', TreePanel1.getSelectionModel().onNodeClick);" +
    "})");
    Thanks for you help! You can mark as solved.

Similar Threads

  1. [CLOSED] [1.0] Treepanel click node problem with ie9
    By PoloTheMonk in forum 1.x Premium Help
    Replies: 2
    Last Post: Aug 13, 2012, 12:44 PM
  2. No Expanded on click treepanel node!
    By abis in forum 2.x Help
    Replies: 2
    Last Post: Aug 12, 2012, 5:22 AM
  3. Help! How to get the select node in treepanel?
    By cf981231 in forum 1.x Help
    Replies: 2
    Last Post: Jan 27, 2011, 7:30 AM
  4. [CLOSED] TreePanel state: re-select node after refresh
    By ljcorreia in forum 1.x Premium Help
    Replies: 9
    Last Post: Mar 24, 2010, 12:27 PM
  5. Right-click node select in TreePanel?
    By dbassett74 in forum 1.x Help
    Replies: 6
    Last Post: May 14, 2009, 12:17 PM

Tags for this Thread

Posting Permissions