作成日: 2017/06/15 最終更新日: 2017/06/15
文書種別
使用方法
詳細
リストボックス型セルで直接データソースと連結して項目を作成する機能はありませんので、下記サンプルコードのように、ListItems プロパティを使用する方法が考えられます。
◎サンプルコード(VB)
◎サンプルコード(C#)
◎サンプルコード(VB)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If IsPostBack Then
Return
End If
' テスト用データの作成
Dim dt As New Data.DataTable("TEST")
dt.Columns.Add("Code", GetType(String))
dt.Columns.Add("Name", GetType(String))
dt.Rows.Add("1", "AAA")
dt.Rows.Add("2", "BBB")
dt.Rows.Add("3", "CCC")
dt.AcceptChanges()
' SPREADの設定
Dim listCell As New FarPoint.Web.Spread.ListBoxCellType()
Dim max As Integer = dt.Rows.Count - 1
Dim items As FarPoint.Web.Spread.ListItem() = New FarPoint.Web.Spread.ListItem(max) {}
For i As Integer = 0 To max
items(i) = New FarPoint.Web.Spread.ListItem(CStr(dt.Rows(i)("Name")), CStr(dt.Rows(i)("Code")))("Code"))
Next
listCell.ListItems = items
FpSpread1.ActiveSheetView.Columns(1).CellType = listCell
End Sub
If IsPostBack Then
Return
End If
' テスト用データの作成
Dim dt As New Data.DataTable("TEST")
dt.Columns.Add("Code", GetType(String))
dt.Columns.Add("Name", GetType(String))
dt.Rows.Add("1", "AAA")
dt.Rows.Add("2", "BBB")
dt.Rows.Add("3", "CCC")
dt.AcceptChanges()
' SPREADの設定
Dim listCell As New FarPoint.Web.Spread.ListBoxCellType()
Dim max As Integer = dt.Rows.Count - 1
Dim items As FarPoint.Web.Spread.ListItem() = New FarPoint.Web.Spread.ListItem(max) {}
For i As Integer = 0 To max
items(i) = New FarPoint.Web.Spread.ListItem(CStr(dt.Rows(i)("Name")), CStr(dt.Rows(i)("Code")))("Code"))
Next
listCell.ListItems = items
FpSpread1.ActiveSheetView.Columns(1).CellType = listCell
End Sub
◎サンプルコード(C#)
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
// テスト用データの作成
System.Data.DataTable dt = new System.Data.DataTable("TEST");
dt.Columns.Add("Code", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add("1", "AAA");
dt.Rows.Add("2", "BBB");
dt.Rows.Add("3", "CCC");
dt.AcceptChanges();
// SPREADの設定
FarPoint.Web.Spread.ListBoxCellType listCell = new FarPoint.Web.Spread.ListBoxCellType();
int max = dt.Rows.Count - 1;
FarPoint.Web.Spread.ListItem[] items = new FarPoint.Web.Spread.ListItem[max + 1];
for (int i = 0; i <= max; i++)
{
items[i] = new FarPoint.Web.Spread.ListItem(dt.Rows[i]["Name"].ToString(), dt.Rows[i]["Code"].ToString());
}
listCell.ListItems = items;
FpSpread1.ActiveSheetView.Columns[1].CellType = listCell;
}
{
if (IsPostBack)
{
return;
}
// テスト用データの作成
System.Data.DataTable dt = new System.Data.DataTable("TEST");
dt.Columns.Add("Code", typeof(string));
dt.Columns.Add("Name", typeof(string));
dt.Rows.Add("1", "AAA");
dt.Rows.Add("2", "BBB");
dt.Rows.Add("3", "CCC");
dt.AcceptChanges();
// SPREADの設定
FarPoint.Web.Spread.ListBoxCellType listCell = new FarPoint.Web.Spread.ListBoxCellType();
int max = dt.Rows.Count - 1;
FarPoint.Web.Spread.ListItem[] items = new FarPoint.Web.Spread.ListItem[max + 1];
for (int i = 0; i <= max; i++)
{
items[i] = new FarPoint.Web.Spread.ListItem(dt.Rows[i]["Name"].ToString(), dt.Rows[i]["Code"].ToString());
}
listCell.ListItems = items;
FpSpread1.ActiveSheetView.Columns[1].CellType = listCell;
}
旧文書番号
40417