作成日: 2026/07/13 最終更新日: 2026/07/13
文書種別
不具合
状況
回避方法あり
詳細
.NET 10をターゲットフレームワークとするプロジェクトを作成しGcSpreadGridを配置します。アプリケーションの起動後にGcSpreadGridのセルを選択してCtrl+Cを押下すると例外の例外が発生します。
System.StackOverflowException
HResult=0x800703E9
Message=Exception of type 'System.StackOverflowException' was thrown.
本現象はターゲットフレームワークが.NET 8のプロジェクトでは発生しません。
回避方法
デフォルトのCtrl+Cのコピーをキャンセルして独自にセルの値をクリップボードにコピーする方法を使用して回避が可能です。
public MainWindow()
{
InitializeComponent();
this.gcSpreadGrid1.PreviewKeyDown += GcSpreadGrid1_PreviewKeyDown;
}
private void GcSpreadGrid1_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.C && Keyboard.Modifiers == ModifierKeys.Control)
{
if (this.gcSpreadGrid1.ActiveCell != null && !this.gcSpreadGrid1.ActiveCell.IsEditing)
{
MyCopy(gcSpreadGrid1);
e.Handled = true;
}
}
}
private void MyCopy(GcSpreadGrid gcSpreadGrid)
{
var selectionRanges = gcSpreadGrid.SelectedRanges;
if (selectionRanges.Count != 1)
{
return;
}
var text = GetClipboardText(gcSpreadGrid, selectionRanges[0]);
var dataObject = new DataObject();
dataObject.SetText(text);
Clipboard.SetDataObject(dataObject, true);
}
private string GetClipboardText(GcSpreadGrid gcSpreadGrid, CellRange range)
{
int row = range.Row == -1 ? 0 : range.Row;
int column = range.Column == -1 ? 0 : range.Column;
int rowCount = range.RowCount == -1 ? gcSpreadGrid.RowCount : range.RowCount;
int columnCount = range.ColumnCount == -1 ? gcSpreadGrid.ColumnCount : range.ColumnCount;
if (rowCount <= 0 || columnCount <= 0)
{
return string.Empty;
}
var text = new StringBuilder();
for (int rowOffset = 0; rowOffset < rowCount; rowOffset++)
{
if (rowOffset > 0)
{
text.Append("\r\n");
}
for (int columnOffset = 0; columnOffset < columnCount; columnOffset++)
{
if (columnOffset > 0)
{
text.Append('\t');
}
text.Append(gcSpreadGrid.GetCellText(row + rowOffset, column + columnOffset));
}
}
return text.ToString();
}