Click here to Skip to main content
14,827,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I have a query related to treeviewitem ContextMenu. I showed Files and folders in
treeview.Now I want to show different contextmenu for Files and Folders type treeviewitem. I added context menu item on ContextMenu_Opend event based on item type.
But if the previous treeviewitem is selected and I rightclick on other treeviewitem
then it shows contextmenu of previous file type. Here is my code--

C#
private void ctxTreeviewMenu_Opened(object sender, RoutedEventArgs e)
        {

            FolderItem fitem = new FolderItem();                 
            fitem = (FolderItem)fileFolderTreeView.SelectedItem;
            if (fitem==null)
            {
                ctxTreeviewMenu.Items.Clear();
                return;
            }
            if (fitem.ItemType == FolderItemType.Folder)
            {
                ctxTreeviewMenu.Items.Clear();
                RadMenuItem radMenuItem1 = new RadMenuItem();
                radMenuItem1.Header = "New Document";
                ctxTreeviewMenu.Items.Add(radMenuItem1);
                RadMenuItem radMenuItem2 = new RadMenuItem();
                radMenuItem2.Header = "Edit";
                ctxTreeviewMenu.Items.Add(radMenuItem2);
                RadMenuItem radMenuItem3 = new RadMenuItem();
                radMenuItem3.Header = "New Folder";
                ctxTreeviewMenu.Items.Add(radMenuItem3);
                RadMenuItem radMenuItem4 = new RadMenuItem();
                radMenuItem4.Header = "Rename";
                ctxTreeviewMenu.Items.Add(radMenuItem4);
                RadMenuItem radMenuItem5 = new RadMenuItem();
                radMenuItem5.Header = "Delete";
                ctxTreeviewMenu.Items.Add(radMenuItem5);
                RadMenuItem radMenuItem6 = new RadMenuItem();
                radMenuItem6.Header = "Refresh";
                ctxTreeviewMenu.Items.Add(radMenuItem6);
                RadMenuItem radMenuItem7 = new RadMenuItem();
                radMenuItem7.Header = "Properties";
                ctxTreeviewMenu.Items.Add(radMenuItem7);
            }
            else
            {
                ctxTreeviewMenu.Items.Clear();
                RadMenuItem radMenuItem1 = new RadMenuItem();
                radMenuItem1.Header = "Open";
                ctxTreeviewMenu.Items.Add(radMenuItem1);
                RadMenuItem radMenuItem2 = new RadMenuItem();
                radMenuItem2.Header = "Edit";
                ctxTreeviewMenu.Items.Add(radMenuItem2);
                RadMenuItem radMenuItem3 = new RadMenuItem();
                radMenuItem3.Header = "Rename";
                ctxTreeviewMenu.Items.Add(radMenuItem3);
                RadMenuItem radMenuItem4 = new RadMenuItem();
                radMenuItem4.Header = "Delete";
                ctxTreeviewMenu.Items.Add(radMenuItem4);
                RadMenuItem radMenuItem5 = new RadMenuItem();
                radMenuItem5.Header = "Refresh";
                ctxTreeviewMenu.Items.Add(radMenuItem5);
                RadMenuItem radMenuItem6 = new RadMenuItem();
                radMenuItem6.Header = "Properties";
                ctxTreeviewMenu.Items.Add(radMenuItem6);
            }
           
        }   


and this is my Xaml file--

HTML
<grid>
                            <grid.rowdefinitions>
                                <rowdefinition height="*" />
                                <rowdefinition height="200" />
                            </grid.rowdefinitions>
                            <telerik:radtreeview grid.row="0" x:name="fileFolderTreeView" itemtemplate="{StaticResource FolderTemplate}" xmlns:x="#unknown" xmlns:telerik="#unknown">
                            IsLoadOnDemandEnabled="True" LoadOnDemand="fileFolderTreeView_LoadOnDemand" IsRootLinesEnabled="True" SelectionChanged="fileFolderTreeView_SelectionChanged" MouseRightButtonUp="fileFolderTreeView_MouseRightButtonUp">
                                <telerik:radcontextmenu.contextmenu>
                                    <telerik:radcontextmenu x:name="ctxTreeviewMenu" opened="ctxTreeviewMenu_Opened">
                                    </telerik:radcontextmenu>
                                </telerik:radcontextmenu.contextmenu>
                            </telerik:radtreeview>

                            <telerik:radtabcontrol grid.row="1" xmlns:telerik="#unknown">
                                <telerik:radtabitem header="Search">

                                </telerik:radtabitem>
                            </telerik:radtabcontrol>
                        </grid>
Posted
Updated 20-Oct-11 21:49pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900