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

本文介绍如何使用DevExpress控件库中的GridView组件实现单元格状态自定义显示,并通过代码演示如何根据单元格值改变按钮状态,包括禁用和启用状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
            }
        }


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值