即兴添加一下

WinForm DevExpress 添加行内按钮

1.在设计器里面添加一列,设置单元格不可编辑、只读属性

 

 

 

2. 在所在GridView属性里面添加CustomDrawCell事件与RowCellClick事件

        private void gvMain_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e)
        {
             
            if (e.Column.FieldName == "btnReport") // 指定要添加按钮的列
            {
                e.Appearance.BackColor = Color.FromArgb(220, 233, 247); // 设置按钮的背景颜色
                e.Appearance.ForeColor = Color.Black; // 设置按钮的前景颜色
                e.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; // 设置按钮的水平对齐方式
                e.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center; // 设置按钮的垂直对齐方式
                e.DisplayText = "报 工"; // 设置按钮的文本
            }

            
        }
         

        private void gvMain_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {

            if (e.Column.FieldName == "btnReport") // 指定要添加按钮的列
            {
                ///按钮事件
            }

        }

 3.效果图

 

posted @ 2023-08-14 12:02  我本梁人  阅读(273)  评论(0编辑  收藏  举报