SPREAD for ASP.NET 10.0J サンプルコード集 > データ連結 > 特定の列だけ連結する |
SheetViewクラスのAutoGenerateColumnsプロパティをFalseに設定し、列のDataFieldプロパティに連結するフィールドの名前を設定します。
FpSpread1.DataSource = new StockList(); FpSpread1.Sheets[0].AutoGenerateColumns = false; FpSpread1.Sheets[0].Columns[0].DataField = "ProductName";
FpSpread1.DataSource = New StockList() FpSpread1.Sheets(0).AutoGenerateColumns = False FpSpread1.Sheets(0).Columns(0).DataField = "ProductName"
この例では、データソースとして以下のクラスを使用しています。
[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