[原] XAF ListView 凍結列

Posted .NET 學習

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[原] XAF ListView 凍結列相关的知识,希望对你有一定的参考价值。

 技术分享

 

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 凍結列的主要内容,如果未能解决你的问题,请参考以下文章

csharp #XAF #XPO如何添加一个Action,它将在单独的ListView中显示已过滤的详细信息集合

XAF学习笔记之-多表头设计

片段中 ListView 的 setOnItemClickListener

片段中ListView的setOnItemClickListener

片段中的ListView不显示

在片段中添加 ListView