Mar*_*وان 6 c# gridview devexpress xtragrid
这与DevExpess XtraGrid的GridView有关.
我需要drilldown plus icon (+)
从GridView中的任何MasterRow中删除它没有任何数据的ChildRow.
目前,我的GridView中的所有行(MasterRows)都显示了drilldown plus icon (+)
.当drilldown plus icon (+)
被点击,ChildRow显示有相应的数据.但是,如果ChildRow没有数据,则不显示(扩展)ChildRow.我需要使drilldown plus icon (+)
隐形,以便用户在ChildRow中没有数据时看不到它.
我有一个函数来检查ChildRow是否有数据可用,然后允许ChildRow显示(展开)或不显示.
我已经使用GridView.OptionsView.ShowDetailButtons
但隐藏了drilldown plus icons (+)
所有行.这对我不起作用,因为如果没有ChildRow的数据,我只需要隐藏它.
这是我到目前为止的代码:
private void gridView1_MasterRowGetRelationCount(object sender, MasterRowGetRelationCountEventArgs e)
{
e.RelationCount = 1;
}
private void gridView1_MasterRowEmpty(object sender, MasterRowEmptyEventArgs e)
{
e.IsEmpty = IsRelationEmpty(e.RowHandle, e.RelationIndex);
}
bool IsRelationEmpty(int rowHandleX, int relationIndex)
{
Tuple<string, double, double> row = (Tuple<string, double, double>)gridView1.GetRow(rowHandleX);
return rowHandleX == DevExpress.XtraGrid.GridControl.InvalidRowHandle || _tfs._dataDictionary[row.Item1.ToString()].Item2.Count == 0;
}
private void gridView1_MasterRowGetChildList(object sender, MasterRowGetChildListEventArgs e)
{
if (IsRelationEmpty(e.RowHandle, e.RelationIndex))
{
return;
}
Tuple<string, double, double> row = (Tuple<string, double, double>)gridView1.GetRow(e.RowHandle);
e.ChildList = _tfs._dataDictionary[row.Item1.ToString()].Item2.ToList(); // _tfs.DictionaryToList();
}
private void gridView1_MasterRowGetRelationName(object sender, MasterRowGetRelationNameEventArgs e)
{
e.RelationName = "Work Items with no Size Estimate:";
}
Run Code Online (Sandbox Code Playgroud)
任何方向或建议将不胜感激.
提前致谢,
Marwan (^_^)
我建议你按照这个DevExpress线程 - 如何隐藏没有明细记录的主行的禁用展开/折叠按钮
XtraGrid不提供隐藏主细节展开按钮以显示空细节的选项.您可以通过CustomDrawCell事件解决此限制 .
这是必要的代码:
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) {
GridView view = sender as GridView;
if(e.Column.VisibleIndex == 0 && view.IsMasterRowEmpty(e.RowHandle))
(e.Cell as GridCellInfo).CellButtonRect = Rectangle.Empty;
}
}
Run Code Online (Sandbox Code Playgroud)
希望这有帮助..