Colorpicker in contextmenu

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

    Posted 31 Mar 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?

    Thanks!

  2. Answer
    Bozhidar
    Admin
    Bozhidar avatar
    1103 posts

    Posted 05 Apr Link to this post

    Hi,

    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">
        <ContextMenus>
            <telerik:RadTreeViewContextMenu runat="server">
                <Items>
                    <telerik:RadMenuItem>
                        <ItemTemplate>
                            <telerik:RadColorPicker runat="server"></telerik:RadColorPicker>
                        </ItemTemplate>
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="RegularItem"></telerik:RadMenuItem>
                </Items>
            </telerik:RadTreeViewContextMenu>
        </ContextMenus>
        <Nodes>
            <telerik:RadTreeNode Text="Node"></telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>


    Regards,
    Bozhidar
    Telerik
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Roberto
    Roberto avatar
    4 posts
    Member since:
    Jul 2010

    Posted 11 Apr 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