本文主要是介绍【WinForm+DevExpress】GridView 表格Preview功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
效果:
实现:
第一步:添加一个GridControl,设置父容器停靠,设置GridView的OptionsView下的ShowPreview属性为True
因为我们的数据源是手动添加的,所以不设置PreviewFieldName属性
第二步:定义实体类
public class OrderLine{public OrderLine(string product, int count, decimal price){this.product = product;this.count = count;this.price = price;}private string product;public string Product{get { return product; }set { product = value; }}private int count;public int Count{get { return count; }set { count = value; }}private decimal price;public decimal Price{get { return price; }set { price = value; }}}public class Order{public Order(DateTime timeStamp, params OrderLine[] orderLines){ this.timeStamp = timeStamp;this.lines = new List<OrderLine>(orderLines);}private DateTime timeStamp;public DateTime TimeStamp{get { return timeStamp; }set { timeStamp = value; }}private List<OrderLine> lines;public List<OrderLine> Lines{get { return lines; }set { lines = value; }}private decimal CalcValue(){decimal result = 0m;foreach (OrderLine line in lines){result += line.Count + line.Price;}return result;}}
第三步:添加测试数据
public XtraGridDynamicPreviewDemo(){InitializeComponent();List<Order> orders = new List<Order>();orders.AddRange(new Order[]{new Order(DateTime.Now,new OrderLine("zhao",3,8.99m),new OrderLine("qian",3,1.99m)),new Order(DateTime.Now.AddDays(1),new OrderLine("sun",2,4.99m),new OrderLine("li",1,1.99m))});gridControl1.DataSource = orders;}
注意:测试数据需要时两个嵌套的List,如果只是一个List,和普通的表格效果一样
这篇关于【WinForm+DevExpress】GridView 表格Preview功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!