【セル型】 コンボボックス型セルの項目を追加したい
対象製品
SPREAD for ASP.NET 8.0J
詳細
コンボボックス型セルの項目はString型の配列となっています。そのため、ArrayListクラスを利用することでコンボボックス型セルの項目を追加することができます。なお、ArrayListクラスやString型配列の詳細についてはMSDNライブラリをご参照ください。
◎サンプルコード(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 cbstr As String()
cbstr = New String() {"1月", "2月", "3月"}
Dim cmbbx As New FarPoint.Web.Spread.ComboBoxCellType()
cmbbx.ShowButton = True
cmbbx.Items = cbstr
FpSpread1.ActiveSheetView.Cells(1, 1).CellType = cmbbx
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' クライアントの変更を確定します
FpSpread1.SaveChanges()
Dim cmb As FarPoint.Web.Spread.ComboBoxCellType = CType(FpSpread1.ActiveSheetView.GetCellType(1, 1), FarPoint.Web.Spread.ComboBoxCellType)
' ArrayListクラスを利用して項目の追加を行います
Dim al As ArrayList = New ArrayList()
al.AddRange(cmb.Items)
al.Add("4月")
al.Add("5月")
' Items プロパティを再設定します
cmb.Items = CType(al.ToArray(GetType(String)), String())
End Sub
If IsPostBack Then
Return
End If
Dim cbstr As String()
cbstr = New String() {"1月", "2月", "3月"}
Dim cmbbx As New FarPoint.Web.Spread.ComboBoxCellType()
cmbbx.ShowButton = True
cmbbx.Items = cbstr
FpSpread1.ActiveSheetView.Cells(1, 1).CellType = cmbbx
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' クライアントの変更を確定します
FpSpread1.SaveChanges()
Dim cmb As FarPoint.Web.Spread.ComboBoxCellType = CType(FpSpread1.ActiveSheetView.GetCellType(1, 1), FarPoint.Web.Spread.ComboBoxCellType)
' ArrayListクラスを利用して項目の追加を行います
Dim al As ArrayList = New ArrayList()
al.AddRange(cmb.Items)
al.Add("4月")
al.Add("5月")
' Items プロパティを再設定します
cmb.Items = CType(al.ToArray(GetType(String)), String())
End Sub
◎サンプルコード(C#)
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
return;
}
string[] cbstr;
cbstr = new String[] { "1月", "2月", "3月"};
FarPoint.Web.Spread.ComboBoxCellType cmbbx = new FarPoint.Web.Spread.ComboBoxCellType();
cmbbx.ShowButton = true;
cmbbx.Items = cbstr;
FpSpread1.ActiveSheetView.Cells[1, 1].CellType = cmbbx;
}
protected void Button1_Click(object sender, EventArgs e)
{
// クライアントの変更を確定
FpSpread1.SaveChanges();
FarPoint.Web.Spread.ComboBoxCellType cmb = (FarPoint.Web.Spread.ComboBoxCellType)FpSpread1.ActiveSheetView.GetCellType(1, 1);
// ArrayListクラスを利用して項目の追加を行います
System.Collections.ArrayList al = new System.Collections.ArrayList();
al.AddRange(cmb.Items);
al.Add("4月");
al.Add("5月");
// Items プロパティを再設定します
cmb.Items = (string[])al.ToArray(typeof(string));
}
{
if (IsPostBack)
{
return;
}
string[] cbstr;
cbstr = new String[] { "1月", "2月", "3月"};
FarPoint.Web.Spread.ComboBoxCellType cmbbx = new FarPoint.Web.Spread.ComboBoxCellType();
cmbbx.ShowButton = true;
cmbbx.Items = cbstr;
FpSpread1.ActiveSheetView.Cells[1, 1].CellType = cmbbx;
}
protected void Button1_Click(object sender, EventArgs e)
{
// クライアントの変更を確定
FpSpread1.SaveChanges();
FarPoint.Web.Spread.ComboBoxCellType cmb = (FarPoint.Web.Spread.ComboBoxCellType)FpSpread1.ActiveSheetView.GetCellType(1, 1);
// ArrayListクラスを利用して項目の追加を行います
System.Collections.ArrayList al = new System.Collections.ArrayList();
al.AddRange(cmb.Items);
al.Add("4月");
al.Add("5月");
// Items プロパティを再設定します
cmb.Items = (string[])al.ToArray(typeof(string));
}
キーワード
セル型