SPREAD for ASP.NET 10.0J サンプルコード集 > セル型 > コンボボックス型セル > 項目にデータソースを連結する |
コンボボックス型セルのDataSourceプロパティにデータソースを設定します。データソースがコントロールの場合(例えば、Webフォームに配置されたObjectDataSourceの場合など)は、DataSourceIDプロパティにデータソースのIDを設定することもできます。
var myDataSource = new SampleData(); ComboBoxCellType cbCell = new ComboBoxCellType() { ShowButton = true, DataSource = myDataSource, DataValueField = "ID", DataTextField = "Name", UseValue = true }; FpSpread1.Cells[0, 1].CellType = cbCell; //コンボボックス型セルに値を設定します FpSpread1.Cells[0, 1].Value = 2;
Dim myDataSource = New SampleData() Dim cbCell As New ComboBoxCellType() With { .ShowButton = True, .DataSource = myDataSource, .DataValueField = "ID", .DataTextField = "Name", .UseValue = True } FpSpread1.Cells(0, 1).CellType = cbCell 'コンボボックス型セルに値を設定します FpSpread1.Cells(0, 1).Value = 2
この例では、データソースとして以下のクラスを使用しています。
public class Student { public int ID { get; set; } public string Name { get; set; } } public class SampleData:List<Student> { public SampleData() { Add(new Student() { ID = 1, Name = "StudentA" }); Add(new Student() { ID = 2, Name = "StudentB" }); Add(new Student() { ID = 3, Name = "StudentC" }); } }
Public Class Student Public Property ID() As Integer Public Property Name() As String End Class Public Class SampleData Inherits List(Of Student) Public Sub New() Add(New Student() With {.ID = 1, .Name = "StudentA"}) Add(New Student() With {.ID = 2, .Name = "StudentB"}) Add(New Student() With {.ID = 3, .Name = "StudentC"}) End Sub End Class