1. 程式人生 > >Dev DevExpress之treelist右鍵選單實現

Dev DevExpress之treelist右鍵選單實現

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               

新增BarManager和popupMenu元件:


設定popupMenu元件的Manager屬性:


右鍵點選popupMenu主鍵,點選Customize選項新增選單



程式碼:

using System;using System.Collections.Generic;using System.Linq;using System.Data;using DevExpress.XtraTreeList;using DevExpress.XtraTreeList.Nodes;using DZAMS.DBUtility;using System.Windows.Forms;using DevExpress.XtraEditors;using System.Drawing;namespace DZAMS.Admin{    public
partial class MenuInfo_Frm : DevExpress.XtraEditors.XtraForm    {        public MenuInfo_Frm()        {            InitializeComponent();         }        private
void MenuInfo_Frm_Load(object sender, EventArgs e)       
{            string strSql = "select * from dbo.DZ_MenuInfo order by PARENTID,ID,SORTINDEX ASC";            DataTable tblDatas = SqlHelper.ExecuteDataset(SqlHelper.conn, CommandType.Text, strSql).Tables[0];            //設定欄位             treeList1.KeyFieldName = "ID";            treeList1.ParentFieldName = "PARENTID";            treeList1.DataSource = tblDatas;            //遞迴設定圖示             //DevTreeListView.SetImageIndex(tlCategory, null, 1, 0);            treeList1.ExpandAll();            treeList1.LookAndFeel.UseDefaultLookAndFeel = false;            treeList1.LookAndFeel.UseWindowsXPTheme = true;        }        private void treeList1_DoubleClick(object sender, EventArgs e)        {            TreeListNode clickedNode = this.treeList1.FocusedNode;            string name = clickedNode.GetDisplayText("NAME");            string formname = clickedNode.GetDisplayText("FORMNAME");        }        private void treeList1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)        {            if (e.Button == MouseButtons.Right)            {                treeList1.ContextMenuStrip = null;                             TreeListHitInfo hInfo = treeList1.CalcHitInfo(new Point(e.X, e.Y));                TreeListNode node = hInfo.Node;                treeList1.FocusedNode = node;                if (node != null)                {                    treeList1.ContextMenuStrip = contextMenuStrip1;                }            }        }        private void treeList1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)        {            TreeList tree = sender as TreeList;            if (e.Button == MouseButtons.Right                    && ModifierKeys == Keys.None                    && treeList1.State == TreeListState.Regular)            {                Point p = new Point(Cursor.Position.X, Cursor.Position.Y);                TreeListHitInfo hitInfo = tree.CalcHitInfo(e.Location);                if (hitInfo.HitInfoType == HitInfoType.Cell)                {                    tree.SetFocusedNode(hitInfo.Node);                }                if (tree.FocusedNode != null)                {                    popupMenu1.ShowPopup(p);                }            }        }        private void barbtnTop_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)        {        }        private void barbtnSub_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)        {        }        private void barbtnModify_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)        {        }        private void barbtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)        {            TreeListNode clickedNode = this.treeList1.FocusedNode;            string name = clickedNode.GetDisplayText("NAME");            string formname = clickedNode.GetDisplayText("FORMNAME");            XtraMessageBox.Show("您確定要刪除" + formname+"嗎?", "警告");        }    }}

效果:



           

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述