SPREAD for Windows Forms 10.0J サンプルコード集
アクティブセルのセル型を取得する

セル型を判断する場合はSheetViewクラスメンバであるGetCellTypeメソッド呼び出しを行い、 is演算子(VB.NETの場合はTypeOf 〜 Is演算子)と併用することで行います。

【実行例】

セル型の取得

 private void Form1_Load(object sender, System.EventArgs e)
 {

  //ボタン型セルを定義します
  FarPoint.Win.Spread.CellType.ButtonCellType b = new FarPoint.Win.Spread.CellType.ButtonCellType();
  fpSpread1.ActiveSheet.Cells[0, 0].CellType = b;

  //コンボボックス型セルを定義します
  FarPoint.Win.Spread.CellType.ComboBoxCellType c = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
  c.Items = new string[] {"aaa", "bbb", "ccc"};
  fpSpread1.ActiveSheet.Cells[0, 1].CellType = c;

  //日付型セルを定義します
  FarPoint.Win.Spread.CellType.DateTimeCellType d = new FarPoint.Win.Spread.CellType.DateTimeCellType();
  fpSpread1.ActiveSheet.Cells[0, 2].CellType = d;

 }

 private void button1_Click(object sender, System.EventArgs e)
 {

  //アクティブセルのインデックスを取得します
  int iRow = fpSpread1.ActiveSheet.ActiveRowIndex;
  int iCol = fpSpread1.ActiveSheet.ActiveColumnIndex;

  //アクティブセルのセル型を判断します
  if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is FarPoint.Win.Spread.CellType.ButtonCellType)
    Console.WriteLine("アクティブセルはボタン型です");
  else if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is FarPoint.Win.Spread.CellType.ComboBoxCellType)
    Console.WriteLine("アクティブセルはコンボボックス型です");
  else if (fpSpread1.ActiveSheet.GetCellType(iRow, iCol) is FarPoint.Win.Spread.CellType.DateTimeCellType)
    Console.WriteLine("アクティブセルは日付型です");
  else
    Console.WriteLine("アクティブセルは標準型です");

 }
 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load

  'ボタン型セルを定義します
  Dim b As New FarPoint.Win.Spread.CellType.ButtonCellType
  FpSpread1.ActiveSheet.Cells(0, 0).CellType = b

  'コンボボックス型セルを定義します
  Dim c As New FarPoint.Win.Spread.CellType.ComboBoxCellType
  c.Items = New String() {"aaa", "bbb", "ccc"}
  FpSpread1.ActiveSheet.Cells(0, 1).CellType = c

  '日付型セルを定義します
  Dim d As New FarPoint.Win.Spread.CellType.DateTimeCellType
  FpSpread1.ActiveSheet.Cells(0, 2).CellType = d

 End Sub

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

  'アクティブセルのインデックスを取得します
  Dim iRow As Integer = FpSpread1.ActiveSheet.ActiveRowIndex
  Dim iCol As Integer = FpSpread1.ActiveSheet.ActiveColumnIndex

  'アクティブセルのセル型を判断します
  If TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is FarPoint.Win.Spread.CellType.ButtonCellType Then
    Console.WriteLine("アクティブセルはボタン型です")
  ElseIf TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is FarPoint.Win.Spread.CellType.ComboBoxCellType Then
    Console.WriteLine("アクティブセルはコンボボックス型です")
  ElseIf TypeOf (FpSpread1.ActiveSheet.GetCellType(iRow, iCol)) Is FarPoint.Win.Spread.CellType.DateTimeCellType Then
    Console.WriteLine("アクティブセルは日付型です")
  Else
    Console.WriteLine("アクティブセルは標準型です")
  End If

 End Sub

 

 


© 2004-2017, GrapeCity inc. All rights reserved.