How to easily create popup menu for DevExpress treelist z

http://www.itjungles.com/how-to-easily-create-popup-menu-for-devexpress-treelist.html

Adding popup menu to DevExpress treelist is an easy task. Follow these simple steps to accomplish this:

1. Once you have the project setup and you have added the treelist to your Windows form. Go to the Toolbox and added in BarManager and Popup Menu. It is located under the section DX.9.3: Navigation & Layout.

devexpress-treelist-popu-menu


2. Now below for your form designer there will be two items. Click on the ResultMenu property and assign the barManager1 to the Manager property.

devexpress-treelist-popu-menu2       >>>>>>>   devexpress-treelist-popu-menu3

3. Now you will need to add some code to the CloseUp event for the popup menu. Double click on the CloseUp event so that it will automatically generate the event handler in the code behind file.

devexpress-treelist-popu-menu4

private void ResultMenu_CloseUp(object sender, EventArgs e)

        {

            if (NeedRestoreFocused)

                tlFuncLoc.FocusedNode = SavedFocused;

        }

4. Now you need to write some code to the treelist MouseUp event.

On the treelist properties windows double click on the MouseUp event.

private void tlFuncLoc_MouseUp(object sender, MouseEventArgs e)

{

    TreeList tree = sender as TreeList;

    if (e.Button == MouseButtons.Right && ModifierKeys == Keys.None && tree.State == TreeListState.Regular)

    {

        Point pt = tree.PointToClient(MousePosition);

        TreeListHitInfo info = tree.CalcHitInfo(pt);

        if (info.HitInfoType == HitInfoType.Cell)

        {

            SavedFocused = tree.FocusedNode;

            int SavedTopIndex = tree.TopVisibleNodeIndex;

            tree.FocusedNode = info.Node;

            NeedRestoreFocused = true;

            ResultMenu.ShowPopup(MousePosition);

        }

    }

}

5. Add the two below variable to the top of the class.

TreeListNode SavedFocused;

bool NeedRestoreFocused;

6. Now click on Customize on the Popup menu to start adding the menu item. Double click on the menu item to create the event handler for that menu item.

devexpress-treelist-popu-menu5

devexpress-treelist-popup-menu5

Addtional examples:

http://www.devexpress.com/Support/Center/KB/p/A915.aspxhttp://www.devexpress.com/Help/?document=XtraBars/CustomDocument5472.htm&levelup=true

原文地址:https://www.cnblogs.com/zeroone/p/3758325.html