我想将UltraGridRow克隆到UltraGridRow的新实例中并仅更改两个单元格。然后我想将这个新的UltraGridRow实例添加到我的Band。
我正在寻找一种方法,不必逐个检查每个Cell,将它们复制到新实例中。
有没有明智而有效的方法来做到这一点?
非常感谢, 卡瓦
答案 0 :(得分:0)
UltraGridRow有一个CopyFrom方法可以完成这个技巧(documentation)。这是对您的场景的测试:
[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
}