2012-08-30 40 views
6

Điều này liên quan đến GridView của DevExpess XtraGrid.Xóa biểu tượng Drilldown Plus (+) khỏi XtraGrid GridView's MasterRow khi ChildRow không có dữ liệu

Tôi cần xóa drilldown plus icon (+) khỏi bất kỳ MasterRow nào trong GridView không có bất kỳ dữ liệu nào cho ChildRow.

Hiện tại, tất cả các hàng (MasterRows) trong GridView của tôi hiển thị drilldown plus icon (+). Khi nhấp chuột drilldown plus icon (+), ChildRow được hiển thị với dữ liệu thích hợp. Tuy nhiên, nếu ChildRow không có dữ liệu thì ChildRow sẽ không được hiển thị (mở rộng). Tôi cần phải ẩn drilldown plus icon (+) để người dùng không nhìn thấy nó nếu không có dữ liệu trong ChildRow.

Tôi có chức năng kiểm tra xem dữ liệu có sẵn cho ChildRow không, sau đó cho phép ChildRow hiển thị (mở rộng) hay không.

Tôi đã sử dụng GridView.OptionsView.ShowDetailButtons nhưng ẩn số drilldown plus icons (+) trên tất cả các hàng. Điều đó không hiệu quả với tôi vì tôi chỉ cần giấu nó nếu không có dữ liệu cho ChildRow.

Đây là mã mà tôi có cho đến nay:

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

Bất kỳ hướng hoặc gợi ý sẽ được đánh giá rất nhiều.

Cảm ơn trước,

Marwan (^_^)

Trả lời

6

tôi đề nghị bạn làm theo chủ đề này DevExpress - How to hide disabled expand/collapse buttons for master rows without detail records

Các XtraGrid không cung cấp một tùy chọn để ẩn master-chi tiết mở rộng các nút để biết chi tiết trống. Bạn có thể giải quyết giới hạn này thông qua sự kiện CustomDrawCell.

Đây là mã cần thiết:

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

Hope trợ giúp này ..

+0

này làm việc thật đẹp ... Cảm ơn! –