[Shift]+矢印キーでセル範囲が選択されるとき、自動マージが含まれていると例外が発生する

文書番号 : 39427     文書種別 : 不具合     登録日 : 2016/06/03     最終更新日 : 2016/12/07
文書を印刷する
対象製品
SPREAD for WPF 1.0J
状況
修正済み
詳細
[Shift]+矢印キーでセルの選択範囲を拡張するとき、行や列に自動マージが設定され、選択範囲にマージが行われるセルが含まれると例外が発生します。
回避方法
Service Pack 3(v1.0.2016.1207)で修正済みです。
Service Pack 3(v1.0.2016.1207)より前のバージョンでは次の回避方法が有効です。
------------------------------------------

コントロールのSelectionChangedイベントを次のように実装することで回避可能です。

◎サンプルコード(VB)
Private Sub GcSpreadGrid1_SelectionChanged(sender As Object, e As EventArgs) Handles GcSpreadGrid1.SelectionChanged
  Dim ranges = GcSpreadGrid1.SelectedRanges.ToArray()
  Dim replace As Boolean = False

  For i As Integer = 0 To ranges.Length - 1
    Dim range = ranges(i)
    If range.RowCount = -1 And range.ColumnCount = -1 Then
      replace = True
      ranges(i) = New CellRange(0, 0, GcSpreadGrid1.RowCount, GcSpreadGrid1.ColumnCount)
    ElseIf range.RowCount = -1 Then
      replace = True
      ranges(i) = New CellRange(0, range.Column, GcSpreadGrid1.RowCount, range.ColumnCount)
    ElseIf range.ColumnCount = -1 Then
      replace = True
      ranges(i) = New CellRange(range.Row, 0, range.RowCount, GcSpreadGrid1.ColumnCount)
    End If
  Next

  If replace Then
    For i As Integer = 0 To i < ranges.Length - 1
      If i = 0 Then
        GcSpreadGrid1.Select(ranges(i), SelectionType.New)
      Else
        GcSpreadGrid1.Select(ranges(i), SelectionType.Add)
      End If
    Next
  End If
End Sub

◎サンプルコード(C#)
void gcSpreadGrid1_SelectionChanged(object sender, System.EventArgs e)
{
  
  var ranges = this.gcSpreadGrid1.SelectedRanges.ToArray();
  bool replace = false;
  for (int i = 0; i < ranges.Length; i++)
  {
    var range = ranges[i];
    if (range.RowCount == -1 && range.ColumnCount == -1)
    {
      replace = true;
      ranges[i] = new CellRange(0, 0, this.gcSpreadGrid1.RowCount, this.gcSpreadGrid1.ColumnCount);
    }
    else if (range.RowCount == - 1)
    {
      replace = true;
      ranges[i] = new CellRange(0, range.Column, this.gcSpreadGrid1.RowCount, range.ColumnCount);
    }
    else if (range.ColumnCount == -1)
    {
      replace = true;
      ranges[i] = new CellRange(range.Row, 0, range.RowCount, this.gcSpreadGrid1.ColumnCount);
    }
  }
  if (replace)
  {
    for (int i = 0; i < ranges.Length; i++)
    {
      this.gcSpreadGrid1.Select(ranges[i], i == 0 ? SelectionType.New : SelectionType.Add);
    }
  }
}