SPREAD for ASP.NET 10.0J サンプルコード集 > グループ化 > コードからグループ化する |
GroupDataModelクラスのGroupメソッドを使用します。
//データを連結します FpSpread1.DataSource = new StockList(); //グループ化を有効にします FpSpread1.Sheets[0].AllowGroup = true; FpSpread1.Sheets[0].GroupBarVisible = true; FpSpread1.Sheets[0].GroupingPolicy = FarPoint.Web.Spread.Model.GroupingPolicy.ExpandParents; FarPoint.Web.Spread.Model.GroupDataModel groupModel = new FarPoint.Web.Spread.Model.GroupDataModel(FpSpread1.Sheets[0].DataModel); SortInfo[] sortInfo = new SortInfo[] { new SortInfo(0,true), //第1キー:1列目を昇順 new SortInfo(3,true) //第2キー:4列目を昇順 }; //グループ化します groupModel.Group(sortInfo); FpSpread1.ActiveSheetView.DataModel = groupModel;
'データを連結します FpSpread1.DataSource = New StockList() 'グループ化を有効にします FpSpread1.Sheets(0).AllowGroup = True FpSpread1.Sheets(0).GroupBarVisible = True FpSpread1.Sheets(0).GroupingPolicy = FarPoint.Web.Spread.Model.GroupingPolicy.ExpandParents Dim groupModel As New FarPoint.Web.Spread.Model.GroupDataModel(FpSpread1.Sheets(0).DataModel) Dim sortInfo As SortInfo() = New SortInfo() _ { New SortInfo(0, True), '第1キー:1列目を昇順 New SortInfo(3, True) '第2キー:4列目を昇順 } 'グループ化します groupModel.Group(sortInfo) FpSpread1.ActiveSheetView.DataModel = groupModel
この例では、データソースとして以下のクラスを使用しています。
[Serializable] public class Stock { public string ProductCode { get; set; } public string ProductName { get; set; } public DateTime StockDate { get; set; } public string NoteNo { get; set; } public DateTime ExpireDate { get; set; } public string LotNo { get; set; } public int Quantity { get; set; } public string Term { get; set; } public double UnitPrice { get; set; } public string Section { get; set; } public string StoreID { get; set; } } [Serializable] public class StockList : List<Stock> { public StockList() { Add(new Stock { ProductCode = "0000001", ProductName = "スイートアーモンド", StockDate = DateTime.Today.AddDays(-9), NoteNo = "D040000004", ExpireDate = DateTime.Today.AddMonths(1), LotNo = "2011092001", Quantity = 200, Term = "本", UnitPrice = 90, Section = "仕入", StoreID = "MYG1001" }); Add(new Stock { ProductCode = "0000001", ProductName = "スイートアーモンド", StockDate = DateTime.Today.AddDays(-9), NoteNo = "D040000004", ExpireDate = DateTime.Today.AddMonths(1), LotNo = "2011092003", Quantity = 400, Term = "本", UnitPrice = 90, Section = "仕入", StoreID = "MYG1001" }); Add(new Stock { ProductCode = "0000001", ProductName = "スイートアーモンド", StockDate = DateTime.Today.AddDays(-6), NoteNo = "D040000001", ExpireDate = DateTime.Today.AddMonths(1), LotNo = "0000001", Quantity = 490, Term = "本", UnitPrice = 90, Section = "製造", StoreID = "MYG1001" }); Add(new Stock { ProductCode = "0000002", ProductName = "グレープシード", StockDate = DateTime.Today.AddDays(-4), NoteNo = "D040000007", ExpireDate = DateTime.Today.AddMonths(2), LotNo = "20111119001", Quantity = 10, Term = "本", UnitPrice = 120, Section = "仕入", StoreID = "MYG1001" }); Add(new Stock { ProductCode = "0000002", ProductName = "グレープシード", StockDate = DateTime.Today.AddDays(-5), NoteNo = "M040000002", ExpireDate = DateTime.Today.AddMonths(2), LotNo = "123", Quantity = 4, Term = "本", UnitPrice = 100, Section = "製造", StoreID = "MYG1001" }); Add(new Stock { ProductCode = "0000003", ProductName = "オリーブ", StockDate = DateTime.Today.AddDays(-9), NoteNo = "D040000006", ExpireDate = DateTime.Today.AddMonths(3), LotNo = "20111119010", Quantity = 9, Term = "本", UnitPrice = 2000, Section = "仕入", StoreID = "MYG1002" }); Add(new Stock { ProductCode = "0000005", ProductName = "馬油", StockDate = DateTime.Today.AddDays(-7), NoteNo = "D040000009", ExpireDate = DateTime.Today.AddYears(1), LotNo = "20111214002", Quantity = 84, Term = "Kg", UnitPrice = 3200, Section = "仕入", StoreID = "MYG1001" }); Add(new Stock { ProductCode = "0000006", ProductName = "ビーワックス", StockDate = DateTime.Today.AddDays(-2), NoteNo = "D040000011", ExpireDate = DateTime.Today.AddYears(1), LotNo = "20111217004", Quantity = 150, Term = "Kg", UnitPrice = 1500, Section = "製造", StoreID = "MYG1002" }); Add(new Stock { ProductCode = "0000010", ProductName = "えごま", StockDate = DateTime.Today.AddDays(-3), NoteNo = "D040000008", ExpireDate = DateTime.Today.AddMonths(1), LotNo = "20111120002", Quantity = 52, Term = "本", UnitPrice = 120, Section = "仕入", StoreID = "MYG1002" }); } }
<Serializable> Public Class Stock Public Property ProductCode() As String Public Property ProductName() As String Public Property StockDate() As DateTime Public Property NoteNo() As String Public Property ExpireDate() As DateTime Public Property LotNo() As String Public Property Quantity() As Integer Public Property Term() As String Public Property UnitPrice() As Double Public Property Section() As String Public Property StoreID() As String End Class <Serializable> Public Class StockList Inherits List(Of Stock) Public Sub New() Add(New Stock() With { .ProductCode = "0000001", .ProductName = "スイートアーモンド", .StockDate = DateTime.Today.AddDays(-9), .NoteNo = "D040000004", .ExpireDate = DateTime.Today.AddMonths(1), .LotNo = "2011092001", .Quantity = 200, .Term = "本", .UnitPrice = 90, .Section = "仕入", .StoreID = "MYG1001" }) Add(New Stock() With { .ProductCode = "0000001", .ProductName = "スイートアーモンド", .StockDate = DateTime.Today.AddDays(-9), .NoteNo = "D040000004", .ExpireDate = DateTime.Today.AddMonths(1), .LotNo = "2011092003", .Quantity = 400, .Term = "本", .UnitPrice = 90, .Section = "仕入", .StoreID = "MYG1001" }) Add(New Stock() With { .ProductCode = "0000001", .ProductName = "スイートアーモンド", .StockDate = DateTime.Today.AddDays(-6), .NoteNo = "D040000001", .ExpireDate = DateTime.Today.AddMonths(1), .LotNo = "0000001", .Quantity = 490, .Term = "本", .UnitPrice = 90, .Section = "製造", .StoreID = "MYG1001" }) Add(New Stock() With { .ProductCode = "0000002", .ProductName = "グレープシード", .StockDate = DateTime.Today.AddDays(-4), .NoteNo = "D040000007", .ExpireDate = DateTime.Today.AddMonths(2), .LotNo = "20111119001", .Quantity = 10, .Term = "本", .UnitPrice = 120, .Section = "仕入", .StoreID = "MYG1001" }) Add(New Stock() With { .ProductCode = "0000002", .ProductName = "グレープシード", .StockDate = DateTime.Today.AddDays(-5), .NoteNo = "M040000002", .ExpireDate = DateTime.Today.AddMonths(2), .LotNo = "123", .Quantity = 4, .Term = "本", .UnitPrice = 100, .Section = "製造", .StoreID = "MYG1001" }) Add(New Stock() With { .ProductCode = "0000003", .ProductName = "オリーブ", .StockDate = DateTime.Today.AddDays(-9), .NoteNo = "D040000006", .ExpireDate = DateTime.Today.AddMonths(3), .LotNo = "20111119010", .Quantity = 9, .Term = "本", .UnitPrice = 2000, .Section = "仕入", .StoreID = "MYG1002" }) Add(New Stock() With { .ProductCode = "0000005", .ProductName = "馬油", .StockDate = DateTime.Today.AddDays(-7), .NoteNo = "D040000009", .ExpireDate = DateTime.Today.AddYears(1), .LotNo = "20111214002", .Quantity = 84, .Term = "Kg", .UnitPrice = 3200, .Section = "仕入", .StoreID = "MYG1002" }) Add(New Stock() With { .ProductCode = "0000006", .ProductName = "ビーワックス", .StockDate = DateTime.Today.AddDays(-2), .NoteNo = "D040000011", .ExpireDate = DateTime.Today.AddYears(1), .LotNo = "20111217004", .Quantity = 150, .Term = "Kg", .UnitPrice = 1500, .Section = "製造", .StoreID = "MYG1002" }) Add(New Stock() With { .ProductCode = "0000010", .ProductName = "えごま", .StockDate = DateTime.Today.AddDays(-3), .NoteNo = "D040000008", .ExpireDate = DateTime.Today.AddMonths(1), .LotNo = "20111120002", .Quantity = 52, .Term = "本", .UnitPrice = 120, .Section = "仕入", .StoreID = "MYG1002" }) End Sub End Class