DJ메탈짱™의 Free Style

Infragstics, Wingrid, Cell, RightClick, ContextMenu, MenuItems, 울트라그리드, 셀, 우클릭, 메뉴아이템 본문

일(job)/MS(Microsoft)

Infragstics, Wingrid, Cell, RightClick, ContextMenu, MenuItems, 울트라그리드, 셀, 우클릭, 메뉴아이템

뽀&쏭 2016. 1. 7. 13:23

Infragstics, Wingrid, Cell, RightClick, ContextMenu, MenuItems, 울트라그리드, 셀, 우클릭, 메뉴아이템         

 

        /// <summary> 

        /// 셀에 대한 마우스 우클릭(ContextMenu) MenuItem 설정

        /// </summary>

        /// <param name="mousePoint"></param>

        private void ShowContextMenu(Point mousePoint)

        {

            ContextMenu cMenu = new ContextMenu();           

            for (int i = 0; i < 3; i++)

            { 

              cMenu.MenuItems.Add(i.ToString(), MenuItemClick);                 

            } 

            foreach (MenuItem c in cMenu.MenuItems)

            {

                if (c.Index == 1)

                {

                    c.Enabled = false;

                }

            }

            cMenu.Show(this.keGrid1, mousePoint);

        } 

 

        /// <summary> 

        /// 셀에 대한 마우스 우클릭(ContextMenu) MenuItem 설정

        /// </summary>

        /// <param name="mousePoint"></param>

        private void ShowContextMenu(Point mousePoint)

        {

            ContextMenu cMenu = new ContextMenu();           

            for (int i = 0; i < 3; i++)

            { 

                cMenu.MenuItems.Add(i.ToString(), MenuItemClick);                 

            }

            foreach (MenuItem c in cMenu.MenuItems)

            {

                if (c.Index == 1) // 첫번째 아이템은 선택되지 않도록 Disabled

                {

                    c.Enabled = false;

                }

            }

            cMenu.Show(this.keGrid1, mousePoint);

        } 

 

  

        /// <summary>  

        /// 셀에 대한 마우스 우클릭(ContextMenu) 설정.  

        /// </summary>  

        /// <param name="sender"></param>  

        /// <param name="e"></param> 

        private void keGrid1_MouseDown(object sender, MouseEventArgs e)

        { 

            // 마우스 우클릭 

            if (e.Button == MouseButtons.Right)

            {

                Point mousePoint = new Point(e.X, e.Y); // 마우스 우클릭시 좌표

                UIElement element = this.keGrid1.DisplayLayout.UIElement.ElementFromPoint(e.Location);

                if (element == null || element.Parent == null) return;

                Infragistics.Shared.ISelectableItem theitem = element.SelectableItem;

                if (theitem is UltraGridCell)

                { 

                    // 선택된 셀 정보를 가져오기. 

                    UltraGridCell cell = element.GetContext(typeof(UltraGridCell)) as UltraGridCell;

                    if (cell != null)

                    {

                        CellUIElement element2 = (CellUIElement)cell.GetUIElement();

                        Point p = new Point(element2.Rect.X, element2.Rect.Y); 

                        this.keGrid1.ActiveRow = ((UltraGridCell)theitem).Row;

                        this.keGrid1.ActiveCell = theitem as UltraGridCell; 

                        // 선택된 셀의 좌측부분에 메뉴아이템이 보여짐. 

                        this.ShowContextMenu(p);

                    } 

                } 

                else

                {

                    this.keGrid1.ContextMenu = null;

                }

            }

        }