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

Context Menu Disable Enable Condition and Node Name Validation.

3 Answers 230 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Krantikumar Jain
Top achievements
Rank 1
Krantikumar Jain asked on 19 Feb 2010, 03:12 PM
Hi

I am using Treeview control to create Levels called Layers (folders) and insurers (Files). I have added Add Layer and Add Insurer Context Menu items when Right clicking on Layer. I want to achieve following things.

1.Disable add new layer and add new Insurer context menu when you right click on an existing insurer name.

Add validation to prevent adding two layers with the same name at same Layer?


Thanks,
Krantikumar Jain

Below is my code.
TRV_DEMO.aspx


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TRV_DEMO.aspx.vb" ValidateRequest="false" Inherits="TreeViewControl.TRV_DEMO"
    Title="Tree View Control DEMO" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>


<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <table border="0" cellpadding="5" cellspacing="5" width="800" >
            <tr>
                <td>
                    <div>
                        <asp:Panel runat="server" ID="pnl1" BorderColor="Maroon">
                            <table>
                                <tr>
                                    <td style="height: 50px">
                                        <asp:Button ID="btnGrp" runat="server" Text="Add Layer" />
                                        <asp:Button ID="btnChild" runat="server" Text="Add Insurer" />
                                    </td>
                                    <td style="height: 50px">
                                        <asp:Button ID="btnInsurerDelete" runat="server" Text="Delete Insurer" /></td>
                                    <td style="height: 50px">
                                        <asp:Button ID="btnDeleteLayer" runat="server" Text="Delete Layer" /></td>
                                </tr>
                            </table>
                        </asp:Panel>
                    </div>
                    <br />
                    <br />
                    <br />
                    <asp:Panel runat="server" ID="Pnl2">
                        <div>
                            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
                            </telerik:RadScriptManager>
                            <script type="text/javascript">
            //<!--
                function onClientContextMenuShowing(sender, args)
                {
                    var treeNode = args.get_node();
                    treeNode.set_selected(true);
                    //enable/disable menu items
                    setMenuItemsState(args.get_menu().get_items(), treeNode);
                }
                
                function onClientContextMenuItemClicking(sender, args)
                {
                    var menuItem = args.get_menuItem();
                    var treeNode = args.get_node();
                    menuItem.get_menu().hide();
                    
                    switch(menuItem.get_value())
                    {
                        case "Copy":
                            break;
                        case "Rename":
                            treeNode.startEdit();
                            break;
                        case "NewLayer":
                            break;
                        case "NewInsurer":
                            break;    
                        case "Delete":
                            var result = confirm("Are you sure you want to delete the item: " + treeNode.get_text());
                            args.set_cancel(!result);
                            break;                            
                    }
                }
 
           
                //this method disables the appropriate context menu items
                function setMenuItemsState(menuItems, treeNode)
                {
                    for (var i=0; i<menuItems.get_count(); i++)
                    {
                        var menuItem = menuItems.getItem(i);
                        switch(menuItem.get_value())
                        {
                            case "Copy":
                                formatMenuItem(menuItem, treeNode, 'Copy "{0}"');
                                break;
                            case "Rename":
                                formatMenuItem(menuItem, treeNode, 'Rename "{0}"');
                                break;
                            case "Delete":
                                formatMenuItem(menuItem, treeNode, 'Delete "{0}"');
                                break;                                
                            case "NewLayer":
                                if (treeNode.get_parent() == treeNode.get_treeView())
                                {
                                    menuItem.set_enabled(true);
                                }
                                else
                                {
                                    menuItem.set_enabled(true);
                                }
                          
                                break;
                            case "NewInsurer":
                                if (treeNode.get_parent() == treeNode.get_treeView())
                                {
                                    menuItem.set_enabled(true);
                                }
                                else
                                {
                                    menuItem.set_enabled(true);
                                }
                          
                                break;    
                        }
                    }
                }
                
                //formats the Text of the menu item
                function formatMenuItem(menuItem, treeNode, formatString)
                {
                    var nodeValue = treeNode.get_value();
                    if (nodeValue && nodeValue.indexOf("_Private_") == 0)
                    {
                        menuItem.set_enabled(false);
                    }
                    else
                    {
                        menuItem.set_enabled(true);
                    }
                    var newText = String.format(formatString, extractTitleWithoutMails(treeNode));
                    menuItem.set_text(newText);
                }
            
             //checks if the text contains (digit)
                function hasNodeMails(treeNode)
                {
                    return treeNode.get_text().match(/\([\d]+\)/ig);
                }
                
                //removes the brackets with the numbers,e.g. Inbox (30)
                function extractTitleWithoutMails(treeNode)
                {
                    return treeNode.get_text().replace(/\s*\([\d]+\)\s*/ig, "");
                }
                
            //-->
                            </script>

                        </div>
                    </asp:Panel>
                    <table  style="border: solid 1px #000; width: 100%; height: 400px; overflow: auto; vertical-align: top;" cellpadding="5" cellspacing="5">
                        <tr>
                            <td>
                                <asp:Panel runat="server" ID="pnlTV">
                                    <telerik:RadTreeView ID="RadTreeView1" runat="server" AllowNodeEditing="true" OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick"
                                        OnClientContextMenuItemClicking="onClientContextMenuItemClicking" OnClientContextMenuShowing="onClientContextMenuShowing"
                                        OnNodeClick="RadTreeView1_NodeClick" OnNodeEdit="RadTreeView1_NodeEdit">
                                        <ContextMenus>
                                            <telerik:RadTreeViewContextMenu ID="MainContextMenu" runat="server">
                                                <Items>
                                                    <telerik:RadMenuItem Value="Copy" Text="Copy ..." ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem Value="Rename" Text="Rename ..." Enabled="false" ImageUrl=""
                                                        PostBack="false">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem Value="NewLayer" Text="New Layer" ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem Value="NewInsurer" Text="New Insurer" ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem Value="Delete" Text="Delete Folder" ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem IsSeparator="true">
                                                    </telerik:RadMenuItem>
                                                </Items>
                                                <CollapseAnimation Type="none" />
                                            </telerik:RadTreeViewContextMenu>
                                            <telerik:RadTreeViewContextMenu ID="EmptyLayerContextMenu" runat="server">
                                                <Items>
                                                    <telerik:RadMenuItem Value="NewLayer" Text="New Layer" ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                     <telerik:RadMenuItem Value="NewInsurer" Text="New Insurer" ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem IsSeparator="true">
                                                    </telerik:RadMenuItem>
                                                    <telerik:RadMenuItem Value="EmptyLayer" Text="Empty this Layer" ImageUrl="">
                                                    </telerik:RadMenuItem>
                                                </Items>
                                                <CollapseAnimation Type="none" />
                                            </telerik:RadTreeViewContextMenu>
                                        </ContextMenus>
                                        <Nodes>
                                            <telerik:RadTreeNode runat="server"  Text="POLICY" Expanded="true" ImageUrl="Images/Layer.jpg"  AllowDrag="false">
                                            </telerik:RadTreeNode>
                                        </Nodes>
                                    </telerik:RadTreeView>
                                </asp:Panel>
                            </td>
                            <td>
                                <div>
                                    <asp:Panel runat="server" ID="pnlGrp" Visible="false">
                                        <table border="2" cellpadding="5" cellspacing="5">
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Layer" runat="server" Text="Layer"></asp:Label>
                                                </td>
                                                <td>
                                                 <telerik:RadTextBox  ID="txtLayer" runat="server">
                                                  </telerik:RadTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Label2" runat="server" Text="Percentage (%)"></asp:Label>
                                                </td>
                                                <td>
                                                 <telerik:RadNumericTextBox  Type="Percent" ID="txtLayerPercentage" runat="server">
                                                        <NumberFormat AllowRounding="true" />
                                                  </telerik:RadNumericTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Button ID="btnAddLayer" runat="server" Text="Add Layer" />
                                                </td>
                                                <td>
                                                    <asp:Button ID="btnEditLayer" runat="server" Text="Edit Layer" />
                                                </td>
                                            </tr>
                                        </table>
                                    </asp:Panel>
                                </div>
                                <div>
                                    <asp:Panel runat="server" ID="pnlChild" Visible="false">
                                        <table border="2" cellpadding="5" cellspacing="5">
                                       <%--    <asp:DropDownList ID="ddInsurer" runat="server" OnSelectedIndexChanged="ddInsurer_SelectedIndexChanged">
                                                        <asp:ListItem>ALL STATE</asp:ListItem>
                                                        <asp:ListItem>NATION WIDE</asp:ListItem>
                                                        <asp:ListItem>PROGRESSIVE</asp:ListItem>
                                                        <asp:ListItem>GEICO</asp:ListItem>
                                                        <asp:ListItem>ESURANCE</asp:ListItem>
                                                        <asp:ListItem>AIG-AUTO</asp:ListItem>
                                                    </asp:DropDownList>
                                                --%> <tr>
                                                <td>
                                                    <asp:Label ID="lbleInsuree" runat="server" Text="Insurer"></asp:Label>
                                                </td>
                                                <td>
                                                  <telerik:RadComboBox AllowCustomText="true" Enabled="true" runat="server" ID="cmbInsurer" Width="150px">
                                                        <Items>
                                                            <telerik:RadComboBoxItem Text="" Value=""></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="21st Century" Value="21st Century"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="ALL STATE" Value="ALL STATE"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="FARMERS INSURANCE" Value="FARMERS INSURANCE"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="NATION WIDE" Value="NATION WIDE"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="PROGRESSIVE" Value="PROGRESSIVE"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="GEICO" Value="GEICO"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="ESURANCE" Value="ESURANCE"></telerik:RadComboBoxItem>
                                                            <telerik:RadComboBoxItem Text="AIG-AUTO" Value="AIG-AUTO"></telerik:RadComboBoxItem>
                                                        </Items>
                                                    </telerik:RadComboBox>
                                                </td>
                                            </tr>    
                                              <%--  <tr>
                                                    <td>
                                                        <asp:Label ID="Label1" runat="server" Text="Insurer"></asp:Label></td>
                                                    <td>
                                                    <telerik:RadTextBox  ID="txtInsurer" runat="server">
                                                      </telerik:RadTextBox>
                                                    </td>
                                                </tr>--%>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="InsPer" runat="server" Text="Percentage (%)"></asp:Label>
                                                </td>
                                                <td>
                                                 <telerik:RadNumericTextBox  Type="Percent" ID="txtPercentage" runat="server">
                                                        <NumberFormat AllowRounding="true" />
                                                  </telerik:RadNumericTextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Button ID="btnInsurerAdd" runat="server" Text="Add Insurer" />
                                                </td>
                                                <td>
                                                    <asp:Button ID="btnInsurerEdit" runat="server" Text="Edit Insurer" />
                                                </td>
                                            </tr>
                                        </table>
                                    </asp:Panel>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <br />
                    <br />
                    <br />
                    <br />
                    <table>
                        <tr>
                            <td>
                                <asp:Button ID="btnXML" runat="server" Text="Export XML" />
                            </td>
                            <td>
                                <asp:Button ID="btnClear" runat="server" Text="Clear XML" Visible="false" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:TextBox ID="txtXML" runat="server" Height="294px" TextMode="MultiLine" Width="673px"
                                    Visible="false"></asp:TextBox></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

Code behind file TRV_DEMO.aspx.vb




Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Text.RegularExpressions
Imports Telerik.Web.UI
Imports System.IO
Imports System.Xml


Partial Public Class TRV_DEMO
    Inherits System.Web.UI.Page
    Protected Const unreadPattern As String = "\(\d+\)"

    'Diabled all the panels and Delete Layer and Delete Insure buttons
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        pnlGrp.Visible = False
        pnlChild.Visible = False
        btnDeleteLayer.Enabled = False
        btnInsurerDelete.Enabled = False


    End Sub

    Protected Sub btnGrp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGrp.Click

        'Enable the Group Layer creation panel
        pnlGrp.Visible = True
        pnlChild.Visible = False
        'Disable the Edit option while adding the Layer
        btnEditLayer.Visible = False
        btnAddLayer.Visible = True
        txtLayer.Text = ""
        txtLayerPercentage.Text = ""
    End Sub

    Protected Sub btnChild_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnChild.Click

        'Enable the Group Layer creation panel
        pnlChild.Visible = True
        pnlGrp.Visible = False

        'Disable the Edit option while adding the Insurer
        btnInsurerEdit.Visible = False
        btnInsurerAdd.Visible = True
        cmbInsurer.Text = ""
        txtPercentage.Text = ""
    End Sub



    'this method is used by Mark All as Read and Empty this folder
    Protected Sub EmptyLayer(ByVal node As RadTreeNode, ByVal removeChildNodes As Boolean)
        node.Font.Bold = False
        node.Text = Regex.Replace(node.Text, unreadPattern, "")

        If removeChildNodes Then
            'Empty this folder is clicked
            Dim i As Integer = node.Nodes.Count - 1
            While i >= 0
                node.Nodes.RemoveAt(i)
                System.Math.Max(System.Threading.Interlocked.Decrement(i), i + 1)
            End While
        Else
            'Mark all as read is clicked
            For Each child As RadTreeNode In node.Nodes
                EmptyLayer(child, removeChildNodes)
            Next
        End If
    End Sub

    Protected Sub RadTreeView1_ContextMenuItemClick(ByVal sender As Object, ByVal e As RadTreeViewContextMenuEventArgs)
        Dim clickedNode As RadTreeNode = e.Node
        If (clickedNode.Value <> "") Then
            e.MenuItem.Enabled = False
        End If

        Select Case e.MenuItem.Value
            Case "Copy"
                Dim clonedNode As RadTreeNode = clickedNode.Clone()
                clonedNode.Text = String.Format("Copy of {0}", clickedNode.Text)
                clickedNode.InsertAfter(clonedNode)
                'set node's value so we can find it in startNodeInEditMode
                clonedNode.Value = clonedNode.GetFullPath("/")
                clonedNode.Selected = True
                startNodeInEditMode(clonedNode.Value)
                Exit Select
            Case "NewLayer"
                Dim NewLayer As New RadTreeNode(String.Format("New Layer {0}", clickedNode.Nodes.Count + 1))
                NewLayer.Selected = True
                NewLayer.ImageUrl = clickedNode.ImageUrl
                clickedNode.Nodes.Add(NewLayer)
                clickedNode.Expanded = True
                'update the number in the brackets
                'If Regex.IsMatch(clickedNode.Text, unreadPattern) Then
                '    clickedNode.Text = Regex.Replace(clickedNode.Text, unreadPattern, "(" + clickedNode.Nodes.Count.ToString() + ")")
                'Else
                '    clickedNode.Text += String.Format(" ({0})", clickedNode.Nodes.Count)
                'End If
                ' clickedNode.Font.Bold = True
                'set node's value so we can find it in startNodeInEditMode
                'NewLayer.Value = NewLayer.GetFullPath("/")
                'startNodeInEditMode(NewLayer.Value)
                Exit Select
            Case "NewInsurer"
                Dim NewLayer As New RadTreeNode(String.Format("New Insurer {0}", clickedNode.Nodes.Count + 1))
                NewLayer.Selected = True
                NewLayer.ImageUrl = "Images/Insurer.jpg"
                NewLayer.Value = "9"
                clickedNode.Nodes.Add(NewLayer)
                clickedNode.Expanded = True
                'update the number in the brackets
                'If Regex.IsMatch(clickedNode.Text, unreadPattern) Then
                '    clickedNode.Text = Regex.Replace(clickedNode.Text, unreadPattern, "(" + clickedNode.Nodes.Count.ToString() + ")")
                'Else
                '    clickedNode.Text += String.Format(" ({0})", clickedNode.Nodes.Count)
                'End If
                ' clickedNode.Font.Bold = True
                'set node's value so we can find it in startNodeInEditMode
                'NewLayer.Value = NewLayer.GetFullPath("/")
                'startNodeInEditMode(NewLayer.Value)
                Exit Select
            Case "EmptyLayer"
                EmptyLayer(clickedNode, True)
                Exit Select
            Case "Delete"
                clickedNode.Remove()
                Exit Select
        End Select
    End Sub
    Private Sub startNodeInEditMode(ByVal nodeValue As String)
        'find the node by its Value and edit it when page loads
        Dim js As String = "Sys.Application.add_load(editNode); function editNode(){ "
        js += "var tree = $find(""" + RadTreeView1.ClientID + """);"
        js += "var node = tree.findNodeByValue('" + nodeValue + "');"
        js += "if (node) node.startEdit();"
        js += "Sys.Application.remove_load(editNode);};"

        RadScriptManager.RegisterStartupScript(Page, Page.[GetType](), "nodeEdit", js, True)
    End Sub

    Protected Sub btnAddLayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddLayer.Click

        'Dim foundNode As RadTreeNode = RadTreeView1.FindNodeByText("ROOT_NODE")
    
        ''TextBox1.Text = ""
        ''Dim foundNode As RadTreeNode = RadTreeView1.FindNodeByText("GROUP 2")
        'If foundNode IsNot Nothing Then
        '    tbResults.Text = foundNode.Text
        'End If
        Dim newNode As New RadTreeNode(RadTreeView1.SelectedNode.Text)
        'Dim rtv As New RadTreeView

        'rtv = RadTreeView1

        'If rtv.SelectedNode.Text = Nothing Then
        '    '    'nothing is selected then create LAYER under root node
        '    RadTreeView1.SelectedNode.Text = "POLICY"
        'End If

        newNode.Value = ""

        If (txtLayerPercentage.Text = "") Then
            txtLayer.Text = txtLayer.Text
        Else
            txtLayer.Text = txtLayer.Text & " (" & txtLayerPercentage.Text & "%" & ")"
        End If
        newNode.Text = txtLayer.Text
        newNode.ImageUrl = "Images/Layer.jpg"


        'RadTreeView1.Nodes.Add(newNode)
        RadTreeView1.SelectedNode.Nodes.Add(newNode)

        'Add to the dropdown box
        ' ddInsurer.Items.Add(New ListItem(newNode.Text))


    End Sub


    Protected Sub btnDeleteLayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteLayer.Click
        'TextBox1.Text = ""
        'If RadTreeView1.SelectedNode <> Nothing Then
        RadTreeView1.SelectedNode.Remove()
        ' or ...
        'RadTreeView1.Nodes.Remove(RadTreeView1.SelectedNode)
        ' or ...
        'RadTreeView1.SelectedNode.ParentNode.Nodes.RemoveAt(RadTreeView1.SelectedNode.Index)
        'End If

    End Sub

    Protected Sub btnInsurerAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsurerAdd.Click

        Dim newNode As New RadTreeNode()
        If (txtPercentage.Text = "") Then
            newNode.Text = cmbInsurer.Text
        Else
            newNode.Text = cmbInsurer.Text & " (" & txtPercentage.Text & "%" & ")"
        End If
        newNode.ImageUrl = "Images/Insurer.jpg"
        newNode.Value = "9"
        RadTreeView1.SelectedNode.Nodes.Add(newNode)
        'Add to the dropdown box
        '      ddInsurer.Items.Add(New ListItem(newNode.Text))


    End Sub

    Protected Sub btnXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXML.Click

        Dim tv As New RadTreeView

        txtXML.Text = ""
        tv.LoadXmlString(RadTreeView1.GetXml())
        txtXML.Text = RadTreeView1.GetXml()
        tv = RadTreeView1()

        txtXML.Visible = True

        exportToXml(RadTreeView1.GetXml(), "C:\\Temp\\cal_xml.xml")

    End Sub

    Public Shared Sub exportToXml(ByVal tv As String, ByVal filename As String)

        Dim XmlDocument As New XmlDocument()

        XmlDocument.LoadXml(tv)
        XmlDocument.Save(filename)

    End Sub


    Protected Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtXML.Text = ""
    End Sub

    'Protected Sub ddInsurer_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddInsurer.SelectedIndexChanged
    '     Dim strInsurer As String = ""

    '    strInsurer = ddInsurer.SelectedIndex

    'End Sub

    Protected Sub RadTreeView1_NodeClick(ByVal o As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeClick
        Dim str As String
        Dim numPos As Int32 = 1
        Dim strPer As String = "%"
        Dim numUSPos As Int32 = 1
        Dim numLen As Int32 = 0
        Dim numLenParent As Int32 = 0
        Dim strParent As String

        txtPercentage.Text = ""
        txtLayerPercentage.Text = ""
        strParent = e.Node.Text
        str = e.Node.Text
        numLen = Len(str)
        numLenParent = Len(strParent)
        numPos = InStr(str, strPer)
        numUSPos = InStr(str, "(")


        If InStr(str, "(") Then
            str = str.Substring(0, numUSPos - 1)
            txtLayerPercentage.Text = Trim(strParent.Substring(numUSPos, numLenParent - 2 - numUSPos))
            txtPercentage.Text = Trim(strParent.Substring(numUSPos, numLenParent - 2 - numUSPos))
        End If
        If str = "POLICY" Then
            pnlGrp.Visible = False
            pnlChild.Visible = False
            btnAddLayer.Visible = True
            btnEditLayer.Visible = False
            txtLayer.Text = ""
            btnDeleteLayer.Visible = True
            btnChild.Enabled = True
            btnGrp.Enabled = True
        Else
            If e.Node.Value = "" Then
                'pnlGrp.Visible = True
                'pnlChild.Visible = False
                'btnAddLayer.Visible = False
                'btnEditLayer.Visible = True
                'txtLayer.Text = str
                'btnDeleteLayer.Visible = True
                'btnChild.Enabled = False
                'btnGrp.Visible = True

                pnlGrp.Visible = True
                pnlChild.Visible = False
                btnAddLayer.Visible = False
                btnEditLayer.Visible = True
                txtLayer.Text = str

                btnDeleteLayer.Enabled = True
                btnChild.Enabled = True
                btnGrp.Enabled = True

            Else
                'pnlChild.Visible = True
                'pnlGrp.Visible = False
                'btnInsurerAdd.Visible = False
                'btnInsurerEdit.Visible = True
                cmbInsurer.SelectedValue = str
                'btnInsurerDelete.Visible = True
                'btnGrp.Visible = True
                'btnChild.Enabled = False
                pnlChild.Visible = True
                pnlGrp.Visible = False

                btnInsurerAdd.Visible = False
                btnInsurerEdit.Visible = True
                cmbInsurer.Text = str
                btnInsurerDelete.Enabled = True
                btnGrp.Enabled = False
                btnChild.Enabled = False

            End If
        End If

        'strParent = e.Node.ParentNode.Text.ToString()

    End Sub 'RadTreeView1_NodeClick

    Protected Sub RadTreeView1_NodeEdit(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeNodeEditEventArgs) Handles RadTreeView1.NodeEdit
        Dim nodeEdited As RadTreeNode = e.Node
        Dim newText As String = e.Text

        nodeEdited.Text = newText
    End Sub


    Protected Sub btnInsurerEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsurerEdit.Click
        If (txtPercentage.Text = "") Then
            RadTreeView1.SelectedNode.Text = cmbInsurer.Text
        Else
            RadTreeView1.SelectedNode.Text = cmbInsurer.Text & " (" & txtPercentage.Text & "%" & ")"
        End If


    End Sub

    Protected Sub btnEditLayer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditLayer.Click
        If (txtLayerPercentage.Text = "") Then
            RadTreeView1.SelectedNode.Text = txtLayer.Text
        Else
            RadTreeView1.SelectedNode.Text = txtLayer.Text & " (" & txtLayerPercentage.Text & "%" & ")"
        End If
    End Sub


    Protected Sub btnInsurerDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsurerDelete.Click
        'If RadTreeView1.SelectedNode <> Nothing Then
        RadTreeView1.SelectedNode.Remove()
        ' or ...
        'RadTreeView1.Nodes.Remove(RadTreeView1.SelectedNode)
        ' or ...
        'RadTreeView1.SelectedNode.ParentNode.Nodes.RemoveAt(RadTreeView1.SelectedNode.Index)
        'End If

    End Sub
End Class



3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 24 Feb 2010, 01:20 PM
Hi Krantikumar Jain,

For the first issue you can use OnClientContextMenuShowing event and enable/disable the items using the client-side API of the context menu.

Regarding the second question, I suggest you use OnClientNodeEditing event and cancel the editing of the node in case there's another node with the same text.

Regards,
Yana
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Dave
Top achievements
Rank 1
answered on 25 Aug 2012, 10:28 PM
More broken links - waste of time.
0
Kate
Telerik team
answered on 27 Aug 2012, 01:08 PM
Hi Dave,

You can refer to the different help articles below:
  • Client-side API of the contextmenu:
  1. http://www.telerik.com/help/aspnet-ajax/menu-client-side-objects.html
  2. http://www.telerik.com/help/aspnet-ajax/menu-radmenuitem-client-side.html


Kind regards,
Kate
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Krantikumar Jain
Top achievements
Rank 1
Answers by
Yana
Telerik team
Dave
Top achievements
Rank 1
Kate
Telerik team
Share this question
or