Devexpress - GridControl 动态禁用按钮

原文:https://www.devexpress.com/Support/Center/Question/Details/A2815/how-to-display-disabled-buttons-for-particular-cells-within-a-buttonedit-column
能打开的,就打开看吧,不然再往看!这里我只用其中的一个方法.

重写方法

//1. 重绘下单元格
 private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            var entity = this.gridView1.GetRow(e.RowHandle) as ddddd;
            if (entity == null) return;
            if (entity.AA == "1")
            {
                var cellinfo = e.Cell;
            }
            if(e.Column.FieldName== "editedit")
            {
                ButtonEditViewInfo buttonEditViewInfo = (ButtonEditViewInfo)((GridCellInfo)e.Cell).ViewInfo;
                if(entity.AA == "1") //这里是你的逻辑
                {
                    buttonEditViewInfo.RightButtons[0].State = DevExpress.Utils.Drawing.ObjectState.Normal;
                }
                else
                {
                    buttonEditViewInfo.RightButtons[0].State = DevExpress.Utils.Drawing.ObjectState.Disabled;
                }
            }

        }

//2。重绘下控件显示时的状态。
 private void gridView1_ShownEditor(object sender, EventArgs e)
        {
            var entity = this.gridView1.GetFocusedRow() as ddddd;
            BaseEdit edit = (sender as DevExpress.XtraGrid.Views.Base.BaseView).ActiveEditor;
            if (edit is ButtonEdit && entity.AA != "1")
            {
                (edit as DevExpress.XtraEditors.ButtonEdit).Properties.Buttons[0].Enabled = false;
            }
        }

效果图

Devexpress - GridControl 动态禁用按钮_第1张图片

附件:
https://download.csdn.net/download/icfhtg/10322728

你可能感兴趣的:(代码片段)