DevExpress XtraGrid 动态自定义控制button按钮显示

private void gvTimeGroup_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
            if (e.Column.FieldName == "IsFinished")
            {
                DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo buttonEditViewInfo = (DevExpress.XtraEditors.ViewInfo.ButtonEditViewInfo)((DevExpress.XtraGrid.Views.Grid.ViewInfo.GridCellInfo)e.Cell).ViewInfo;


                if (e.CellValue.Equals("1"))//判断条件,具体情况另行修改
                {
                    buttonEditViewInfo.RightButtons[0].Button.Enabled = false;//必须有,否则即使button状态为灰色,但点击还会触发事件
                    buttonEditViewInfo.RightButtons[0].State = DevExpress.Utils.Drawing.ObjectState.Disabled;
                }
                else
                {
                    buttonEditViewInfo.RightButtons[0].Button.Enabled = true;
                    buttonEditViewInfo.RightButtons[0].State = DevExpress.Utils.Drawing.ObjectState.Normal;
                }
            }
        }


 

private void gvProject_ShownEditor(object sender, EventArgs e)
        {
            DevExpress.XtraEditors.BaseEdit edit = (sender as DevExpress.XtraGrid.Views.Base.BaseView).ActiveEditor;

            if (edit is DevExpress.XtraEditors.ButtonEdit && edit.EditValue!=null  &&!edit.EditValue.Equals(1))
            {

                (edit as DevExpress.XtraEditors.ButtonEdit).Properties.Buttons[0].Enabled = false;
            }
        }


 

你可能感兴趣的:(object,button)