我想将一个UltraGridRow克隆到一个新的UltraGridRow实例中,并且只更改两个单元格。然后,我想将这个新的UltraGridRow实例添加到我的Band中。
我正在寻找一种方法,不需要逐个遍历每个Cell来将它们复制到新实例中。
有没有什么聪明有效的方法来做到这一点呢?
发布于 2009-10-23 07:45:28
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
}https://stackoverflow.com/questions/1500726
复制相似问题