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

Colorpicker in contextmenu

2 Answers 689 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 1
Roberto asked on 31 Mar 2016, 09:45 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Bozhidar
Telerik team
answered on 05 Apr 2016, 07:43 AM
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.
0
Roberto
Top achievements
Rank 1
answered on 11 Apr 2016, 11:12 PM

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.

Tags
TreeView
Asked by
Roberto
Top achievements
Rank 1
Answers by
Bozhidar
Telerik team
Roberto
Top achievements
Rank 1
Share this question
or