作成日: 2019/06/03 最終更新日: 2019/06/03
文書種別
制限事項
詳細
数式を設定した行を挟んで、Rows.Moveメソッドで行を移動すると、数式の範囲が正しく更新されません。
例えば、A18セルに「=SUM(B1:B17)」という数式を設定しているとき、Rows.Moveメソッドで19行目を17行目をよりも上に移動すると、本来、数式が「=SUM(B1:B18)」と自動更新される必要がありますが、「=SUM(B1:B19)」のように更新されてしまいます。
例えば、A18セルに「=SUM(B1:B17)」という数式を設定しているとき、Rows.Moveメソッドで19行目を17行目をよりも上に移動すると、本来、数式が「=SUM(B1:B18)」と自動更新される必要がありますが、「=SUM(B1:B19)」のように更新されてしまいます。
回避方法
例えば、ボタンの押下で行の移動を行う場合は、次のような処理で行います。
◎サンプルコード(C#)
◎サンプルコード(C#)
public MainWindow()
{
InitializeComponent();
gcSpreadGrid1.RowCount = 19;
gcSpreadGrid1.ColumnCount = 7;
for (int i = 0; i < gcSpreadGrid1.RowCount; i++)
{
gcSpreadGrid1[i, 1].Value = 10;
}
gcSpreadGrid1[17, 0].Formula = "SUM(B1:B17)";
gcSpreadGrid1.CanUserEditFormula = true;
_insert = (InsertCore)(from m in gcSpreadGrid1.Rows.GetType().GetRuntimeMethods()
where m.Name == "InsertOverride"
let @params = m.GetParameters()
where @params.Length == 2 &&
@params[0].ParameterType == typeof(int) &&
@params[1].ParameterType == typeof(int)
select m).Single().
CreateDelegate(typeof(InsertCore), gcSpreadGrid1.Rows);
}
private delegate bool InsertCore(int index, int count);
private readonly InsertCore _insert;
private void button_Click(object sender, RoutedEventArgs e)
{
////Rows.Moveメソッドを使用せずに以下の処理を実行します。
//gcSpreadGrid1.Rows.Move(18, 10, 1);
MoveRow(18, 10);
var oldClipboard = Clipboard.GetDataObject();
var oldActiveCellPos = gcSpreadGrid1.ActiveCellPosition;
var oldSelection = gcSpreadGrid1.SelectedRanges;
gcSpreadGrid1.ResetSelection();
foreach (var rng in oldSelection)
{
gcSpreadGrid1.Select(rng, SelectionType.Add);
}
gcSpreadGrid1.ActiveCellPosition = oldActiveCellPos;
Clipboard.SetDataObject(oldClipboard);
}
private void MoveRow(int fromRow, int toRow)
{
gcSpreadGrid1.Select(new CellRange(fromRow, 0, 1, gcSpreadGrid1.ColumnCount), SelectionType.New);
gcSpreadGrid1.EditCommands.Copy.Execute(null);
gcSpreadGrid1.Rows.Remove(fromRow);
_insert(toRow, 1);
gcSpreadGrid1.Select(new CellRange(toRow, 0, 1, gcSpreadGrid1.ColumnCount), SelectionType.New);
gcSpreadGrid1.EditCommands.Paste.Execute(null);
}
旧文書番号
84012