DevExpress动态禁用GridControl列RepositoryItem

.Net技术 码拜 9年前 (2015-07-14) 3262次浏览 0个评论

Winform项目使用了DevExpress 的GridControl,由于各行数据状态不同,需要动态设置每一行RepositoryItemHyperLinkEdit列的状态。可以操作的行不做处理,不可操作的行设置为只读状态,且不显示操作按钮。

解决方法:

创建两个 RepositoryItemHyperLinkEdit: 一个将 ReadOnly 属性设置为 true, 另一个设置为 false. 根据它们所在列的状态动态设置 GridView.CustomRowCellEdit 事件处理函数:

设置为false的为正常显示(可以操作)时列默认绑定的RepositoryItem。不可操作的设置如下:
private DevExpress.XtraEditors.Repository.RepositoryItemHyperLinkEdit _diabledRepositoryItemHyperLinkEdit = new DevExpress.XtraEditors.Repository.RepositoryItemHyperLinkEdit();

之后可以在构造函数中任意设置_diabledRepositoryItemHyperLinkEdit状态或属性。

 

private void advBandedGridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e)
{
if (e.Column.Name != “bandedGridColumn_Edit”) return;
ExampleModel model = (ExampleModel)_gridView.GetRow(e.RowHandle);
if (model !=null&&model .State.HasValue && model .State.Value ==1) return;
e.RepositoryItem = _diabledRepositoryItemHyperLinkEdit;
}


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明DevExpress动态禁用GridControl列RepositoryItem
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!