|
| 1 | +using DemoCommon.Grid; |
| 2 | +using Syncfusion.Data; |
| 3 | +using Syncfusion.WinForms.DataGrid; |
| 4 | +using Syncfusion.WinForms.DataGrid.Enums; |
| 5 | +using System; |
| 6 | +using System.Collections.ObjectModel; |
| 7 | +using System.ComponentModel; |
| 8 | +using System.Windows.Forms; |
| 9 | + |
| 10 | +namespace AddNewRow |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// Summary description for Form1. |
| 14 | + /// </summary> |
| 15 | + public partial class Form1 : Form |
| 16 | + { |
| 17 | + #region Constructor |
| 18 | + |
| 19 | + OrderInfoCollection orderInfoCollection = new OrderInfoCollection(); |
| 20 | + |
| 21 | + public Form1() |
| 22 | + { |
| 23 | + InitializeComponent(); |
| 24 | + sfDataGrid.DataSource = orderInfoCollection.Orders; |
| 25 | + sfDataGrid.ShowGroupDropArea = true; |
| 26 | + |
| 27 | + this.sfDataGrid.GroupColumnDescriptions.Add(new GroupColumnDescription() |
| 28 | + { |
| 29 | + ColumnName = "Country", |
| 30 | + KeySelector = (string ColumnName, object o) => |
| 31 | + { |
| 32 | + var item = (o as OrderInfo).Country; |
| 33 | + if (item == null || item == "") |
| 34 | + { |
| 35 | + return ""; |
| 36 | + } |
| 37 | + |
| 38 | + return item; ; |
| 39 | + } |
| 40 | + }); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + #endregion |
| 45 | +} |
| 46 | + |
| 47 | + public class OrderInfo : INotifyPropertyChanged |
| 48 | + { |
| 49 | + int orderID; |
| 50 | + string customerId; |
| 51 | + string country; |
| 52 | + string customerName; |
| 53 | + string shippingCity; |
| 54 | + |
| 55 | + public event PropertyChangedEventHandler PropertyChanged; |
| 56 | + |
| 57 | + public int OrderID |
| 58 | + { |
| 59 | + get { return orderID; } |
| 60 | + set |
| 61 | + { |
| 62 | + orderID = value; |
| 63 | + RaisePropertyChanged("OrderID"); |
| 64 | + } |
| 65 | + } |
| 66 | + public string CustomerID |
| 67 | + { |
| 68 | + get { return customerId; } |
| 69 | + set |
| 70 | + { |
| 71 | + customerId = value; |
| 72 | + RaisePropertyChanged("CustomerID"); |
| 73 | + } |
| 74 | + } |
| 75 | + public string CustomerName |
| 76 | + { |
| 77 | + get { return customerName; } |
| 78 | + set |
| 79 | + { |
| 80 | + customerName = value; |
| 81 | + RaisePropertyChanged("CustomerName"); |
| 82 | + } |
| 83 | + } |
| 84 | + public string Country |
| 85 | + { |
| 86 | + get { return country; } |
| 87 | + set |
| 88 | + { |
| 89 | + country = value; |
| 90 | + RaisePropertyChanged("Country"); |
| 91 | + } |
| 92 | + } |
| 93 | + public string ShipCity |
| 94 | + { |
| 95 | + get { return shippingCity; } |
| 96 | + set |
| 97 | + { |
| 98 | + shippingCity = value; |
| 99 | + RaisePropertyChanged("ShipCity"); |
| 100 | + } |
| 101 | + } |
| 102 | + public OrderInfo(int orderId, string customerName, string country, string customerId, string shipCity) |
| 103 | + { |
| 104 | + this.OrderID = orderId; |
| 105 | + this.CustomerName = customerName; |
| 106 | + this.Country = country; |
| 107 | + this.CustomerID = customerId; |
| 108 | + this.ShipCity = shipCity; |
| 109 | + } |
| 110 | + |
| 111 | + /// <summary> |
| 112 | + /// Occurs when any property value changed. |
| 113 | + /// </summary> |
| 114 | + /// <param name="propertyName">The name of the property which was changed.</param> |
| 115 | + private void RaisePropertyChanged(string propertyName) |
| 116 | + { |
| 117 | + if (PropertyChanged != null) |
| 118 | + this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | +public class OrderInfoCollection |
| 123 | +{ |
| 124 | + public ObservableCollection<OrderInfo> _orders; |
| 125 | + public ObservableCollection<OrderInfo> Orders |
| 126 | + { |
| 127 | + get { return _orders; } |
| 128 | + set { _orders = value; } |
| 129 | + } |
| 130 | + public OrderInfoCollection() |
| 131 | + { |
| 132 | + _orders = new ObservableCollection<OrderInfo>(); |
| 133 | + this.GenerateOrders(); |
| 134 | + } |
| 135 | + private void GenerateOrders() |
| 136 | + { |
| 137 | + _orders.Add(new OrderInfo(1001, "Maria Anders", null, "ALFKI", "Berlin")); |
| 138 | + _orders.Add(new OrderInfo(1002, "Ana Trujilo", null, "ANATR", "Mexico D.F.")); |
| 139 | + _orders.Add(new OrderInfo(1003, "Antonio Moreno", null, "ANTON", "Mexico D.F.")); |
| 140 | + _orders.Add(new OrderInfo(1004, "Thomas Hardy", "UK", "AROUT", "London")); |
| 141 | + _orders.Add(new OrderInfo(1005, "Christina Berglund", string.Empty, "BERGS", "Lula")); |
| 142 | + _orders.Add(new OrderInfo(1006, "Hanna Moos", "Germany", "BLAUS", "Mannheim")); |
| 143 | + _orders.Add(new OrderInfo(1007, "Frederique Citeaux", string.Empty, "BLONP", "Strasbourg")); |
| 144 | + _orders.Add(new OrderInfo(1008, "Martin Sommer", "Spain", "BOLID", "Madrid")); |
| 145 | + _orders.Add(new OrderInfo(1009, "Laurence Lebihan", "France", "BONAP", "Marseille")); |
| 146 | + _orders.Add(new OrderInfo(1010, "Elizabeth Lincoln", "Canada", "BOTTM", "Tsawassen")); |
| 147 | + _orders.Add(new OrderInfo(1011, "Maria Anders", null, "ALFKI", "Berlin")); |
| 148 | + _orders.Add(new OrderInfo(1012, "Ana Trujilo", "Mexico", "ANATR", "Mexico D.F.")); |
| 149 | + _orders.Add(new OrderInfo(1013, "Antonio Moreno", "Mexico", "ANTON", "Mexico D.F.")); |
| 150 | + _orders.Add(new OrderInfo(1014, "Thomas Hardy", string.Empty, "AROUT", "London")); |
| 151 | + _orders.Add(new OrderInfo(1015, "Christina Berglund", "Sweden", "BERGS", "Lula")); |
| 152 | + _orders.Add(new OrderInfo(1016, "Hanna Moos", string.Empty, "BLAUS", "Mannheim")); |
| 153 | + _orders.Add(new OrderInfo(1017, "Frederique Citeaux", "France", "BLONP", "Strasbourg")); |
| 154 | + _orders.Add(new OrderInfo(1018, "Martin Sommer", string.Empty, "BOLID", "Madrid")); |
| 155 | + _orders.Add(new OrderInfo(1019, "Laurence Lebihan", "France", "BONAP", "Marseille")); |
| 156 | + _orders.Add(new OrderInfo(1020, "Elizabeth Lincoln", null, "BOTTM", "Tsawassen")); |
| 157 | + } |
| 158 | +} |
0 commit comments