如何在DevExpress Master Detail DataGrid中隐藏某些卡片?

时间:2018-07-16 12:01:40

标签: c# datagridview devexpress devexpress-windows-ui devexpress-gridcontrol

我想在用RowValues列表填充的DataGrid中显示一些(但不是全部)数据:

public class RowValue 
{
    public int id;
    public string name;
    public List<A> list1;
    public List<B> list2;
}

public class A
{
    public int id;
    public string val1;
    public string val2;
    ...
}

public class B
{
    public int id;
    public string val1;
    public string val2;
    ...
}

当我在Master-Detail DataGrid中展开一行时,我看到两张卡显示每个列表(list1和list2)的行。我想隐藏list1以免在DataGrid中查看。目前,我可以隐藏list1中的所有列,但是带有标题的空卡仍在污染GridView。

void gridView_MasterRowExpand(object sender, CustomMasterRowEventArgs e)
{
   var masterView = sender as GridView;
   GridView detailView = masterView?.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
   if(detailView == null) return;

   //disabling Columns
   if(detailView.LevelName == "list1")
       foreach(var column in detailView.Columns)
           column.Visible = false;
}

为了说明我的问题,我在卡片上附上了删除了所有列的图片。

Empty card I wish to remove from view.

1 个答案:

答案 0 :(得分:0)

我成功地完成了这项任务。我认为最简单的答案是在MasterRowEmpty事件中将e.IsEmpty Arg设置为true。参见下面的代码:

void gridView_MasterRowEmpty(object sender, MasterRowEmptyEventArgs e)
{
    GridView view = sender as GridView;
    if(view.GetRelationName(e.RowHandle, e.RelationIndex) == "list1")   // == "Card Name"
        e.IsEmpty = true;
}