【セル型】コンボボックス型セルで選択された要素のValues値を取得する(サーバー側で)

文書番号 : 21875     文書種別 : 使用方法     最終更新日 : 2006/06/23
文書を印刷する
対象製品
SPREAD for .NET 2.5J Web Forms Edition
詳細
コンボボックスのValue値を取得する方法は、サーバー側で処理する方法とクライアント側で処理する方法の2種類あります。ここでは、サーバー側で処理する方法を記載します。

UpdateCommandイベントのe.EditValuesではコンボボックス型セルで選択された要素のItems値を取得することができます。Items値では無く、Values値を取得したいという場合、下記の方法にて可能です。

【VB サンプルコード】
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If IsPostBack Then
      Return
    End If

    Dim cb As New FarPoint.Web.Spread.ComboBoxCellType(New String() {"AAA", "BBB", "CCC"}, New String() {"A", "B", "C"})
    FpSpread1.ActiveSheetView.Columns(1).CellType = cb
  End Sub

  Private Sub FpSpread1_UpdateCommand(ByVal sender As Object, ByVal e As FarPoint.Web.Spread.SpreadCommandEventArgs) Handles FpSpread1.UpdateCommand
    If Not Object.ReferenceEquals(e.EditValues(1), FarPoint.Web.Spread.FpSpread.Unchanged) Then
      Dim cb As FarPoint.Web.Spread.ComboBoxCellType = CType(FpSpread1.ActiveSheetView.Columns(1).CellType, FarPoint.Web.Spread.ComboBoxCellType)
      Dim index As Int32 = Array.IndexOf(cb.Items, e.EditValues(1))
      Dim x As String = cb.Values(index)
      FpSpread1.ActiveSheetView.Cells(e.CommandArgument, 2).Value = x
    End If
  End Sub


【C# サンプルコード】
  private void Page_Load(object sender, System.EventArgs e)
  {
    if (IsPostBack) return;

    FarPoint.Web.Spread.ComboBoxCellType cb = new FarPoint.Web.Spread.ComboBoxCellType(new string[] { "AAA", "BBB", "CCC" }, new string[] { "A", "B", "C" });
    FpSpread1.ActiveSheetView.Columns[1].CellType = cb;
  }

  private void FpSpread1_UpdateCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
  {
    if (!Object.ReferenceEquals(e.EditValues[1], FarPoint.Web.Spread.FpSpread.Unchanged))
    {
      FarPoint.Web.Spread.ComboBoxCellType cb = FpSpread1.ActiveSheetView.Columns[1].CellType as FarPoint.Web.Spread.ComboBoxCellType;
      int index = Array.IndexOf(cb.Items, e.EditValues[1]);
      string x = cb.Values[index];
      FpSpread1.ActiveSheetView.Cells[(int)e.CommandArgument, 2].Value = x;
    }
  }
関連情報
キーワード
セル型

この文書は、以前は次のFAQ IDで公開されていました : 9198