[原] XAF ListView 凍結列

 [原] XAF ListView 凍結列_第1张图片

 

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;
        }
    }
}

 

你可能感兴趣的:([原] XAF ListView 凍結列)