首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何克隆UltraGridRow (信息技术)?

如何克隆UltraGridRow (信息技术)?
EN

Stack Overflow用户
提问于 2009-09-30 21:20:42
回答 1查看 2.5K关注 0票数 1

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

我正在寻找一种方法,不需要逐个遍历每个Cell来将它们复制到新实例中。

有没有什么聪明有效的方法来做到这一点呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-10-23 07:45:28

UltraGridRow有一个CopyFrom方法(documentation),它应该可以做到这一点。以下是针对您的场景的测试:

代码语言:javascript
复制
[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
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1500726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档