シートをスクロールする際にチェックボックス型セルの状態が変わる場合がある

文書番号 : 37652     文書種別 : 不具合     登録日 : 2014/10/27     最終更新日 : 2016/01/12
文書を印刷する
対象製品
SPREAD for WPF 1.0J
状況
修正済み
詳細
シートをスクロールする際にチェックボックス型セルの状態が変わる場合があります。

【手順】
1.新規ウィンドウにSPREADを配置します
2.下記サンプルコードをコピーし、アプリケーションを実行します
3.A1セルとA2セルのチェックボックスをチェックします
4.シートを上下にスクロールします
   --チェックボックス型セルの状態が変わる場合があります

◎サンプルコード(VB)
Public Sub New()
  InitializeComponent()

  ' チェックボックス型セルの設定
  Dim chk As New GrapeCity.Windows.SpreadGrid.CheckBoxCellType()
  GcSpreadGrid1.Columns(0).CellType = chk
End Sub

◎サンプルコード(C#)
public MainWindow()
{
  InitializeComponent();
  
  // チェックボックス型セルの設定
  GrapeCity.Windows.SpreadGrid.CheckBoxCellType chk = new CheckBoxCellType();
  gcSpreadGrid1.Columns[0].CellType = chk;
}


以下のように[Ctrl + X](または[Delete])キーによる切り取り時にもチェックボックス型セルの状態が不正になる現象が発生します。

【手順】
1.新規ウィンドウにSPREADを配置します
2.下記サンプルコードをコピーし、アプリケーションを実行します
3.A列の列ヘッダをクリックします
4.[Ctrl + X]キーを押下します
   --チェックボックス型セルが未選択の状態になります
   ※本来は、チェックボックス型セルがチェックなしの状態になります

◎サンプルコード(VB)
Public Sub New()
  InitializeComponent()

  ' チェックボックス型セルの設定
  Dim chk As New GrapeCity.Windows.SpreadGrid.CheckBoxCellType()
  chk.IsThreeState = False
  chk.TrueContent = "チェックON"
  chk.FalseContent = "チェックOFF"
  chk.IndeterminateContent = "未設定"
  GcSpreadGrid1.Columns(0).CellType = chk

  ' 値の設定
  For i As Integer = 0 To GcSpreadGrid1.RowCount - 1
    GcSpreadGrid1.Cells(i, 0).Value = True
  Next
End Sub

◎サンプルコード(C#)
public MainWindow()
{
  InitializeComponent();

  // チェックボックス型セルの設定
  GrapeCity.Windows.SpreadGrid.CheckBoxCellType chk = new GrapeCity.Windows.SpreadGrid.CheckBoxCellType();
  chk.IsThreeState = false;
  chk.TrueContent = "チェックON";
  chk.FalseContent = "チェックOFF";
  chk.IndeterminateContent = "未設定";
  gcSpreadGrid1.Columns[0].CellType = chk;

  // 値の設定
  for (int i = 0; i < gcSpreadGrid1.RowCount; i++)
  {
    gcSpreadGrid1.Cells[i, 0].Value = true;
  }
}
回避方法
Service Pack 2(v1.0.2015.1109)で修正済み。
Service Pack 2(v1.0.2015.1109)より前のバージョンでは次の回避方法が有効です。
------------------------------------------

セル単位でチェックボックス型セルを設定します。


◎サンプルコード(VB)
Public Sub New()
  InitializeComponent()

  '' チェックボックス型セルの設定
  'Dim chk As New GrapeCity.Windows.SpreadGrid.CheckBoxCellType()
  'GcSpreadGrid1.Columns(0).CellType = chk

  ' セルごとにチェックボックス型セルを設定
  For i As Integer = 0 To GcSpreadGrid1.RowCount - 1
    Dim chk As New GrapeCity.Windows.SpreadGrid.CheckBoxCellType()
    GcSpreadGrid1.Cells(i, 0).CellType = chk
  Next
End Sub

◎サンプルコード(C#)
public MainWindow()
{
  InitializeComponent();
  
  //// チェックボックス型セルの設定
  //GrapeCity.Windows.SpreadGrid.CheckBoxCellType chk = new CheckBoxCellType();
  //gcSpreadGrid1.Columns[0].CellType = chk;

  // セルごとにチェックボックス型セルを設定
  for (int i = 0; i < gcSpreadGrid1.RowCount; i++)
  {
    GrapeCity.Windows.SpreadGrid.CheckBoxCellType chk = new CheckBoxCellType();
    gcSpreadGrid1.Cells[i, 0].CellType = chk;
  }
}


または独自のセル型を作成することで回避することができます。([Ctrl + X]キーの現象については、独自のセル型を作成する必要があります)

◎サンプルコード(VB)
Public Sub New()
  InitializeComponent()

  ' チェックボックス型セルの設定
  'Dim chk As New GrapeCity.Windows.SpreadGrid.CheckBoxCellType()
  Dim chk As New MyCheckBoxCellType()
  chk.IsThreeState = False
  chk.TrueContent = "チェックON"
  chk.FalseContent = "チェックOFF"
  chk.IndeterminateContent = "未設定"
  GcSpreadGrid1.Columns(0).CellType = chk

  ' 値の設定
  For i As Integer = 0 To GcSpreadGrid1.RowCount - 1
    GcSpreadGrid1.Cells(i, 0).Value = True
  Next
End Sub

Public Class MyCheckBoxCellType
  Inherits GrapeCity.Windows.SpreadGrid.CheckBoxCellType
  Protected Overrides Sub SetDisplayValue(displayElement As FrameworkElement, value As Object, text As String, specialForeground As Brush)
    If value Is Nothing Then
      value = False
    End If
    MyBase.SetDisplayValue(displayElement, value, text, specialForeground)
  End Sub
  Protected Overrides Sub SetEditValue(editElement As FrameworkElement, value As Object)
    If value Is Nothing Then
      value = False
    End If
    MyBase.SetEditValue(editElement, value)
  End Sub
End Class

◎サンプルコード(C#)
public MainWindow()
{
  InitializeComponent();

  // チェックボックス型セルの設定
  //GrapeCity.Windows.SpreadGrid.CheckBoxCellType chk = new GrapeCity.Windows.SpreadGrid.CheckBoxCellType();
  MyCheckBoxCellType chk = new MyCheckBoxCellType();
  chk.IsThreeState = false;
  chk.TrueContent = "チェックON";
  chk.FalseContent = "チェックOFF";
  chk.IndeterminateContent = "未設定";
  gcSpreadGrid1.Columns[0].CellType = chk;

  // 値の設定
  for (int i = 0; i < gcSpreadGrid1.RowCount; i++)
  {
    gcSpreadGrid1.Cells[i, 0].Value = true;
  }
}

public class MyCheckBoxCellType : GrapeCity.Windows.SpreadGrid.CheckBoxCellType
{
  protected override void SetDisplayValue(FrameworkElement displayElement, object value, string text, Brush specialForeground)
  {
    if (value == null)
    {
      value = false;
    }
    base.SetDisplayValue(displayElement, value, text, specialForeground);
  }
  protected override void SetEditValue(FrameworkElement editElement, object value)
  {
    if (value == null)
    {
      value = false;
    }
    base.SetEditValue(editElement, value);
  }
}