ActiveCellを参照すると例外が発生する場合がある

文書番号 : 31106     文書種別 : 不具合     最終更新日 : 2011/07/27
文書を印刷する
対象製品
El Tabelle Sheet 4.0J
状況
回避方法あり
詳細
FormにSheetが配置されている。 ※WorkBookにSheetが追加されている場合、本現象は発生しません。
IsR1C1プロパティにTrueが設定されている。
MaxRowsプロパティに0が設定されている。(またはMaxColumnsプロパティに0が設定されている。)
回避方法
以下のいずれかの方法で本現象を回避することができます。

1.WorkBookにSheetを追加して使用する。
2.Sheet.ActivePositionプロパティを参照して、ActiveCellが有効かどうかを判定する。※ 下記のサンプルコードをご参照ください。


[Visual Basic]
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Sheet1.IsR1C1 = True
    Sheet1.MaxColumns = 0
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    '' この処理を実行すると例外が発生します。
    'If Sheet1.ActiveCell Is Nothing Then
    '  MessageBox.Show("Nothing")
    'End If

    ' 回避方法
    If GetActiveCell() Is Nothing Then
      MessageBox.Show("Nothing")
    End If
  End Sub

  Private Function GetActiveCell() As GrapeCity.Win.ElTabelle.Cell

    Dim pos As GrapeCity.Win.ElTabelle.Position = Me.Sheet1.ActivePosition
    If (pos.Column = -1 And pos.Row = -1) Then
      Return Nothing
    Else
      Return Me.Sheet1.ActiveCell
    End If
  End Function




[C#]
  private void Form1_Load(object sender, EventArgs e)
  {
    sheet1.IsR1C1 = false;
    sheet1.MaxColumns = 0;
  }

  private void button1_Click(object sender, EventArgs e)
  {
    //// この処理を実行すると例外が発生します。
    //if (sheet1.ActiveCell == null)
    //{
    //  MessageBox.Show("ActiveCellはありません");
    //}

    // 回避方法
    if (GetActiveCell() == null)
    {
      MessageBox.Show("ActiveCellはありません");
    }
  }

  private GrapeCity.Win.ElTabelle.Cell GetActiveCell()
  {
    GrapeCity.Win.ElTabelle.Position pos = this.sheet1.ActivePosition;
    if (pos.Column == -1 & pos.Row == -1)
    {
      return null;
    }
    else
    {
      return this.sheet1.ActiveCell;
    }
  }
キーワード
ETSH08383