在展开的行周围设置边框
本文关键字:周围 设置 边框 | 更新日期: 2023-09-27 18:32:51
我正在使用带有事件的devexpress xtragrid(C# winforms)将主行动态绑定到详细信息行。展开主行时,我希望在主行和细节行周围设置边框。当主行展开时,我希望该行及其详细信息行周围有一个蓝色框,以使其对用户突出显示。
您可以使用该方法完成任务,该方法基于处理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; }
}