.NET 學習

.NET 學習生活感想... 万事成蹉跎..... 贵在坚持 及时整理自己做过和学过的东西

博客园 首页 新随笔 联系 订阅 管理

 

 

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.Utils.Menu;
using DevExpress.XtraGrid.Menu;
using System.Drawing;
using DevExpress.ExpressApp.Utils;

namespace E1554.Module
{
    public partial class FixclomunViewController : ViewController<ListView>
    {
        public FixclomunViewController()
        {
            InitializeComponent();
          
        }

        protected override void OnDeactivated()
        {
            base.OnDeactivated();            
        }

        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
            GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;
            if (listEditor != null)
            {
                XafGridView gridView = listEditor.GridView as XafGridView;
                gridView.PopupMenuShowing += new PopupMenuShowingEventHandler(gridView_PopupMenuShowing);
            }

        }
        private void gridView_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
        {
            if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column)
            {
                DevExpress.XtraGrid.Menu.GridViewColumnMenu menu = e.Menu as GridViewColumnMenu;              
                
                if (menu.Column != null)
                {
                  
                    //Adding new items
                    DXPopupMenu popMenu = new DXPopupMenu();
                    popMenu.Caption = "凍結列";
                    menu.Items.Add(popMenu);

                    popMenu.Items.Add(CreateCheckItem("取消", menu.Column, FixedStyle.None,
                     ImageLoader.Instance.GetImageInfo("NotFixed").Image));
                    popMenu.Items.Add(CreateCheckItem("左側", menu.Column, FixedStyle.Left,
                     ImageLoader.Instance.GetImageInfo("FixedLeft").Image));
                    popMenu.Items.Add(CreateCheckItem("右側", menu.Column, FixedStyle.Right,
                      ImageLoader.Instance.GetImageInfo("FixedRight").Image));
                }
                
            }
        }

        //Create a menu item 
        DXMenuCheckItem CreateCheckItem(string caption, GridColumn column, FixedStyle style, Image image)
        {
            DXMenuCheckItem item = new DXMenuCheckItem(caption, column.Fixed == style,
              image, new EventHandler(OnFixedClick));
            item.Tag = new MenuInfo(column, style);
            return item;
        }

        //Menu item click handler 
        void OnFixedClick(object sender, EventArgs e)
        {
            DXMenuItem item = sender as DXMenuItem;
            MenuInfo info = item.Tag as MenuInfo;
            if (info == null) return;
            info.Column.Fixed = info.Style;
        }

        //The class that stores menu specific information 
        class MenuInfo
        {
            public MenuInfo(GridColumn column, FixedStyle style)
            {
                this.Column = column;
                this.Style = style;
            }
            public FixedStyle Style;
            public GridColumn Column;
        }
    }
}

 

posted on 2016-03-22 11:19  Tonyyang  阅读(566)  评论(0编辑  收藏  举报
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/