Colorpicker in contextmenu

3 posts, 1 answers
  1. Roberto
    Roberto avatar
    5 posts
    Member since:
    Jul 2010

    Posted 31 Mar 2016 Link to this post

    Is there a way that I can have a colorpicker on the contextmenu of a radtreeview?

    I need to pick a color for the node in javascript.

    If not possible, can I open an auxiliary window and have the return color?


  2. Answer
    Bozhidar avatar
    1180 posts

    Posted 05 Apr 2016 Link to this post


    You can use the ItemTemplate to put an arbitrary server control inside the item of a contextMenu. Here's some sample code:
    <telerik:RadTreeView ID="RadTreeView1" runat="server">
            <telerik:RadTreeViewContextMenu runat="server">
                            <telerik:RadColorPicker runat="server"></telerik:RadColorPicker>
                    <telerik:RadMenuItem Text="RegularItem"></telerik:RadMenuItem>
            <telerik:RadTreeNode Text="Node"></telerik:RadTreeNode>

    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. Roberto
    Roberto avatar
    5 posts
    Member since:
    Jul 2010

    Posted 11 Apr 2016 Link to this post

    It works, but you need to handle the chain of events or you won't be able to choose a color, the context menu closes before you can click the apply button.

    For future reference and if it helps anyone:

    1) Handle the treeview's OnClientContextMenuShowing on  context menu and save the clicked node in a global variable

    2) Handle the treeview's OnClientContextMenuItemClicking and cancel the event if the click was on the colorpicker item (or it will close before applying the new color)

    3) Handle the color picker's OnClientColorChange and do your work, the node will be saved in the global variable. When you are finished close the context menu.

    4) Handle the context menu's OnClientHidden and set the global variable to null.

    1 and 4 only need to be done if you need the node that called the context menu.

Back to Top