【问题标题】:Set a border around expanded row在展开的行周围设置边框
【发布时间】:2016-02-02 15:12:33
【问题描述】:

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

【问题讨论】:

    标签: c# winforms devexpress xtragrid


    【解决方案1】:

    您可以使用基于处理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; }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-16
      • 2015-06-26
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多