在展开的行周围设置边框

时间:2016-02-02 15:12:34

标签: c# winforms devexpress xtragrid

我正在使用带有事件的devexpress xtragrid(C#winforms)来动态地将主行绑定到详细信息行。当我展开主行时,我希望在主行和细节行周围设置边框。当扩展主行时,我希望该行周围有一个蓝色框架及其细节行,以使其在用户中脱颖而出。

1 个答案:

答案 0 :(得分:0)

您可以根据处理GridControl.Paint事件:

,使用该方法完成任务
gridControl1.DataSource = Repository.GetOrders();
// Some Visual Options for details
gridView1.LevelIndent = 0;
gridView1.OptionsDetail.ShowDetailTabs = false;
gridView1.OptionsDetail.AllowOnlyOneMasterRowExpanded = true;
// 
gridControl1.Paint += gridControl1_Paint;
//...
void gridControl1_Paint(object sender, PaintEventArgs e) {
    var viewInfo = gridView1.GetViewInfo() as GridViewInfo;
    foreach(var rowInfo in viewInfo.RowsInfo) {
        if(gridView1.GetMasterRowExpanded(rowInfo.RowHandle))
            e.Graphics.DrawRectangle(Pens.Blue, rowInfo.TotalBounds);
    }
}

数据类:

public static class Repository {
    public static List<Order> GetOrders() {
        return new List<Order> { 
            new Order(){ Id=0, Date = DateTime.Now.AddDays(-1), 
                Items = new List<OrderItem>{
                    new OrderItem(){ Id=0, Name="A"},
                    new OrderItem(){ Id=1, Name="B"},
                }
            },
            new Order(){ Id=1, Date = DateTime.Now, 
                Items = new List<OrderItem>{
                    new OrderItem(){ Id=0, Name="A"},
                    new OrderItem(){ Id=1, Name="B"},
                    new OrderItem(){ Id=1, Name="C"},
                }
            }
        };
    }
}
public class Order {
    public int Id { get; set; }
    public DateTime Date { get; set; }
    public List<OrderItem> Items { get; set; }
}
public class OrderItem {
    public int Id { get; set; }
    public string Name { get; set; }
}