1

我想将 UltraGridRow 克隆到 UltraGridRow 的新实例中并仅更改两个单元格。然后我想将这个新的 UltraGridRow 实例添加到我的 Band 中。

我正在寻找一种不必逐个遍历每个单元以将它们复制到新实例中的方法。

有没有智能有效的方法来做到这一点?

4

1 回答 1

0

UltraGridRow 有一个 CopyFrom 方法应该可以解决问题(文档)。这是针对您的场景的测试:

[Test]
public void CloneRowCellsTest()
{
  UltraGridRow objSource = new UltraGridRow();
  objSource.Cells.Add(new UltraGridCell("Original value for cell 0"));
  objSource.Cells.Add(new UltraGridCell("Original value for cell 1"));

  UltraGridRow objDestination = new UltraGridRow();
  objDestination.CopyFrom(objSource);
  objDestination.Cells[1].Value = "New value for cell 1";

  Assert.AreEqual(objSource.Cells.Count, objDestination.Cells.Count);
  Assert.AreEqual("Original value for cell 0", objDestination.Cells[0].Value);  //Ensure that the value was copied
  Assert.AreEqual("New value for cell 1", objDestination.Cells[1].Value);       //Ensure that the new value was set
  Assert.AreEqual("Original value for cell 1", objSource.Cells[1].Value);       //Ensure that the original was unchanged
}
于 2009-10-22T23:45:27.743 回答