判断 DEV-〉XtraGrid-〉GridView 中某个单元格是否可以被编辑

public bool IsEditableCell(GridColumn col, int rowHandle)
        { 
            if (col == null) 
            { 
                return false; 
            } 
            
            if (!this.view.OptionsBehavior.Editable || !col.OptionsColumn.AllowEdit)
            { 
                return false;
            }
            
            if (!this.view.IsDataRow(rowHandle)) 
            { 
                if (this.view.IsNewItemRow(rowHandle) || this.view.IsFilterRow(rowHandle))
                { 
                    return true;
                }
                else 
                { 
                    return false;
                } 
            } 
            
            object val = this.view.GetRowCellValue(rowHandle, col);

            // 根据FormatCondition,通过HighPriority->ApplyToRow->Index的降序,取得Editable的Default以外有効条件
            var p = from v in this.view.FormatConditions.OfType<BaseFormatCondition>() 
                    where (v.Editable != DefaultBoolean.Default && v.CheckValue(col, val, this.view.GetDataSourceRowIndex(rowHandle))) 
                    orderby (v.Appearance.Options.HighPriority ? 0 : 1), (v.ApplyToRow ? 1 : 0), this.view.FormatConditions.IndexOf(v) 
                    descending select v.Editable; 
            
            return p.Count() == 0 || p.ElementAt(0) == DefaultBoolean.True;
        }
    }


    public class BaseFormatCondition : DevExpress.XtraGrid.StyleFormatCondition
    { 
        public BaseFormatCondition() : base() {} 
        public BaseFormatCondition(FormatConditionEnum condition) : base(condition) { } 
        public BaseFormatCondition(FormatConditionEnum condition,GridColumn column,object tag, object val1) : base(condition,column,tag,val1) { } 
        public BaseFormatCondition(FormatConditionEnum condition, GridColumn column, object tag, object val1, object val2) : base(condition, column, tag, val1, val2) { } 
        public BaseFormatCondition(FormatConditionEnum condition, GridColumn column, object tag, object val1, object val2, bool applyToRow) : base(condition, column, tag, val1, val2,applyToRow) { } 
        public BaseFormatCondition(FormatConditionEnum condition,AppearanceObject appearance, object tag, object val1, object val2, GridColumn column, bool applyToRow) : base(condition, tag, appearance, val1, val2,column, applyToRow) { } 
        
        [Browsable(true)]
        [DefaultValue(DefaultBoolean.Default)]
        [Description("指定条件是否可以编辑")]
        public DefaultBoolean Editable 
        { 
            set
            { 
                _editable = value;
            } 
            
            get
            {
                return _editable;
            } 
        } 
        
        private DefaultBoolean _editable = DefaultBoolean.Default;

        public override void Assign(DevExpress.XtraEditors.StyleFormatConditionBase source) 
        { 
            base.Assign(source);
            
            if (source is BaseFormatCondition) this.Editable = (source as BaseFormatCondition).Editable; 
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值