利用devexpress的gridLookUpEdit制作多选下拉框带过滤

先上效果图

在这里插入图片描述

1, 先写一个 GridCheckMarksSelection 类

    class GridCheckMarksSelection
    {
        #region Fileds
        RepositoryItemGridLookUpEdit _currentRepository;

        protected ArrayList selection;
        protected String checkColumnFieldName = "CheckMarkSelection";
        RepositoryItemCheckEdit edit;
        const Int32 CheckboxIndent = 4;
        #endregion

        #region Construct
        public GridCheckMarksSelection(RepositoryItemGridLookUpEdit repository)
            : this()
        {
            CurrentRepository = repository;
        }

        public RepositoryItemGridLookUpEdit CurrentRepository
        {
            get { return _currentRepository; }
            set
            {
                if (_currentRepository != value)
                {
                    Detach();
                    Attach(value);
                }
            }
        }

        public GridCheckMarksSelection()
        {
            selection = new ArrayList();
            this.OnSelectionChanged();
        }
        #endregion

        #region Attribute
        public ArrayList Selection
        {
            get { return selection; }
            set { selection = value; }
        }

        public Int32 SelectedCount { get { return selection.Count; } }
        #endregion

        #region GridSelect
        public object GetSelectedRow(Int32 index)
        { return selection[index]; }

        public Int32 GetSelectedIndex(object row)
        { return selection.IndexOf(row); }

        public void ClearSelection(GridView currentView)
        {
            selection.Clear();
            Invalidate(currentView);
            OnSelectionChanged();
        }

        public void SelectAll(object sourceObject)
        {
            selection.Clear();
            if (sourceObject != null)
            {
                if (sourceObject is ICollection)
                    selection.AddRange(((ICollection)sourceObject));
                else
                {
                    GridView currentView = sourceObject as GridView;
                    for (Int32 i = 0; i < currentView.DataRowCount; i++)
                        selection.Add(currentView.GetRow(i));
                    Invalidate(currentView);
                }
            }
            this.OnSelectionChanged();
        }

        public delegate void SelectionChangedEventHandler(object sender, EventArgs e);
        public event SelectionChangedEventHandler SelectionChanged;
        public void OnSelectionChanged()
        {
            if (SelectionChanged != null)
            {
                EventArgs e = new EventArgs();
                SelectionChanged(this, e);
            }
        }
        public void SelectGroup(GridView currentView, Int32 rowHandle, bool select)
        {
            if (IsGroupRowSelected(currentView, rowHandle) && select) return;
            for (Int32 i = 0; i < currentView.GetChildRowCount(rowHandle); i++)
            {
                Int32 childRowHandle = currentView.GetChildRowHandle(rowHandle, i);
                if (currentView.IsGroupRow(childRowHandle))
                    SelectGroup(currentView, childRowHandle, select);
                else
                    SelectRow(currentView, childRowHandle, select, false);
            }
            Invalidate(currentView);
        }

        public void SelectRow(GridView currentView, Int32 rowHandle, bool select)
        {
            SelectRow(currentView, rowHandle, select, true);
        }

        public void InvertRowSelection(GridView currentView, Int32 rowHandle)
        {
            if (currentView.IsDataRow(rowHandle))
                SelectRow(currentView, rowHandle, !IsRowSelected(currentView, rowHandle));
            if (currentView.IsGroupRow(rowHandle))
                SelectGroup(currentView, rowHandle, !IsGroupRowSelected(currentView, rowHandle));
        }

        public bool IsGroupRowSelected(GridView currentView, Int32 rowHandle)
        {
   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值