DevExpress GridView 两个问题

1、Column中显示图片

        private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            if (e.Column == this.gridColumnImage && e.IsGetData)
            {
                switch ((e.Row as Messages).Status)
                {
                    case 0: e.Value = global::Jesus.WinApplication.Properties.Resources.mail; break;
                    default: e.Value = global::Jesus.WinApplication.Properties.Resources.blank; break;
                }
            }
        }

gridColumnImage 是Column的Name,注意需设置FieldName为唯一的值,比如设置为列名(否则CustomUnboundColumnData不会被调用)

设置gridColumnImage 的UnBoundType属性为Object

设置gridColumnImage 的ColumnEdit为 PictureEdit


2、代码控制某单元格按钮是否显示,一种方法就是创建一个不可能的buttonedit,然后关联到该单元格

        private void gvSelf_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column.Name == "gridColumnUpdate")
            {

		DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit ritem = new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit();
                ritem.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
                ritem.ReadOnly = true;
                ritem.Buttons[0].Enabled = false;
                ritem.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
                ritem.Buttons[0].Caption = " ";
                e.RepositoryItem = ritem;            
	     }
        }

在更新行数据后,调用gvSelf.CloseEditor() 函数激活界面刷新。否则就只能等切换行时CustomRowCellEdit才会调用



你可能感兴趣的:(DevExpress GridView 两个问题)