c# – 当ChildRow没有数据时从XtraGrid GridView的MasterRow中删除Drilldown Plus图标()

前端之家收集整理的这篇文章主要介绍了c# – 当ChildRow没有数据时从XtraGrid GridView的MasterRow中删除Drilldown Plus图标()前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这与DevExpess XtraGrid的GridView有关.

我需要从GridView中的任何MasterRow中删除drilldown plus icon(),该GridView没有任何ChildRow数据.

目前,我的GridView中的所有行(MasterRows)都显示了drilldown plus icon().单击向下钻取加上icon()时,将显示带有相应数据的ChildRow.但是,如果ChildRow没有数据,则不显示(扩展)ChildRow.我需要使钻取加上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>)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>)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:";
}

任何方向或建议将不胜感激.

提前致谢,

Marwan (^_^)

解决方法

我建议你按照这个DevExpress线程 – How to hide disabled expand/collapse buttons for master rows without detail records

The XtraGrid does not provide an option to hide master-detail expand
buttons for empty details. You can work around this limitation via the
CustomDrawCell event.

这是必要的代码

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;
    }
}

希望这有帮助..

原文链接:https://www.f2er.com/csharp/244416.html

猜你在找的C#相关文章