此网格的父级是项目,而子级是 BOM 。我已经设法使用以下代码显示子网格。
private void gridView_MasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e)
{
Project projects = (Project)gridView.GetRow(e.RowHandle);
e.IsEmpty = projects.BOMs.Count == 0;
}
private void gridView_MasterRowGetRelationCount(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationCountEventArgs e)
{
e.RelationCount = 1;
}
private void gridView_MasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e)
{
e.RelationName = "BOMs";
}
private void gridView_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
{
Project projects = (Project)gridView.GetRow(e.RowHandle);
e.ChildList = new BindingSource(projects, "BOMs");
}
但是,代码显示了所有列。我想隐藏孩子的一些列 BOM 。
我发现的唯一方法是使用下面的内容
dataGridView1.Columns[index].Visible = false;
但我应该在哪里放置上述代码?
更新代码
private void gridView_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
{
GridView gridView = sender as GridView;
GridView detailView = (GridView)gridView.GetDetailView(e.RowHandle, e.RelationIndex);
detailView.Columns["Column Name"].Visible = false;
}
答案 0 :(得分:0)
为了满足您的需求,您必须处理GridControl中的Grid_MasterRowExpanded
方法:
private void Grid_MasterRowExpanded(System.Object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
{
GridView view = sender;
GridView detail = view.GetDetailView(e.RowHandle, e.RelationIndex);
if (e.RowHandle == 0 | e.RowHandle == 1) {
if (detail.Name == "BOM") {
detail.Columns["Column Name"].Visible = false;
}
}
}
答案 1 :(得分:0)