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

[Solved] Having Context Menu targeting Tree View not operate unless node selected

3 Answers 58 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Walter Harris
Top achievements
Rank 1
Walter Harris asked on 05 May 2009, 02:57 PM
I am using the following: VS2008 Team Edition, the 3.5 TreeView Control and the 3.5 Context Menu Control

I have a TreeView Control on my page and a Context Menu control defined to target it (shown below).  I need the Context Menu to not appear unless there is a selected Node in the TreeView Control.  I know I can check for the selected node status in the code behind, but I don't want the menu to appear at all if a node is not selected.

I have thought about using a method to set the menu to enabled true/false, but am trying to not require a postback.  The other option might be to put some javascript in the page.  Anyone have a simple way other than one of these two ways or does the control already have an option to exactly this?

 

<div runat="server" id="left_pane">

 

<telerik:RadTreeView ID="tvCommodityCodes" runat="server" Skin="WebBlue"

 

CheckBoxes="true">

 

 

</telerik:RadTreeView>

 

 

<telerik:RadContextMenu ID="RadContextMenu1" runat="server" Skin="Web20"

 

 

ClickToOpen="true" OnItemClick="RadContextMenu1_ItemClick">

 

 

<CollapseAnimation Duration="1" /> 

 

<Items>

 

<telerik:RadMenuItem runat="server" Text="Add Entry" Value="Add" />  

 

<telerik:RadMenuItem runat="server" Text="Remove Entry" Value="Rem" />  

 

<telerik:RadMenuItem runat="server" Text="Edit Entry" Value="Edt" />  

 

<telerik:RadMenuItem runat="server" IsSeparator="true" />  

 

<telerik:RadMenuItem runat="server" Text="Save Entries" Value="Sav" />  

 

<telerik:RadMenuItem runat="server" Text="Abort Changes" Value="Abt" />  

 

</Items>

 

<Targets>

 

<telerik:ContextMenuControlTarget ControlID="tvCommodityCodes" />

 

 

</Targets>

 

 

</telerik:RadContextMenu>

 

 

</div>

I'm populating the tvCommodityCodes via

 

 

this.tvCommodityCodes.LoadXmlString(new StreamReader (CommodityEditor.Properties.Settings.Default.XMLInputFile).ReadToEnd());

 

 

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 05 May 2009, 03:00 PM
Hello Walter Harris,

I suggest you use the built-in context menu of RadTreeView which behaves exactly as you want to. Please check this example for a reference. You may also check this help topic.

Regards,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Walter Harris
Top achievements
Rank 1
answered on 05 May 2009, 03:05 PM
Thanks Albert, I am now looking at that code. 
0
Walter Harris
Top achievements
Rank 1
answered on 05 May 2009, 07:24 PM
That did the trick and it is working just fine.
Tags
Menu
Asked by
Walter Harris
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Walter Harris
Top achievements
Rank 1
Share this question
or