如何禁用GridView中的列?

时间:2019-02-11 14:54:04

标签: c# gridview datagridview devexpress datagridviewcolumn

我想在detailView的DevExpress GridView中禁用列。现在,我可以通过以下代码在此视图中隐藏列,但不能将这些列设置为只读或未启用:

private void GridView_MasterRowExpanded(object sender, CustomMasterRowEventsArgs e)
{
    var masterView = sender as GridView;
    GridView detailView = masterView?.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
    detailView?.Columns[0].Visible = false;
} 

1 个答案:

答案 0 :(得分:1)

private void GridView_MasterRowExpanded(object sender, CustomMasterRowEventsArgs e)
{
    var masterView = sender as GridView;
    GridView detailView = masterView?.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;

    //Make the column read-only
    detailView?.Columns[0].OptionsColumn.ReadOnly = true;

    //Make the column non-editable
    detailView?.Columns[0].OptionsColumn.AllowEdit = false;
} 

文档: https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Columns.OptionsColumn.ReadOnly.property

https://documentation.devexpress.com/WindowsForms/DevExpress.XtraGrid.Columns.OptionsColumn.AllowEdit.property