1

I would like to clone a UltraGridRow into a new instance of UltraGridRow and change two cells only. Then I would like to add this new UltraGridRow instance to my Band.

I am seeking a way to not have to go through each Cell one by one to copy them into the new instance.

Is there any intelligent and effective way to do this?

Houman
  • 64,245
  • 87
  • 278
  • 460
  • The answer supplied here by [lagerdalek](http://stackoverflow.com/users/5302/lagerdalek) should work for you... [http://stackoverflow.com/questions/78536/cloning-objects-in-c](http://stackoverflow.com/questions/78536/cloning-objects-in-c) – Steve Dignan Oct 01 '09 at 19:36

1 Answers1

0

The UltraGridRow has a CopyFrom method that should do the trick (documentation). Here's a test for your scenario:

[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
}
jrullmann
  • 2,912
  • 1
  • 25
  • 27
  • Thanks for your response. I think this is the solution. BUt I can't apply it since in Infragistics 2006, there seem to be no CopyFrom(). But hopefully when we upgrade around Christmas, I would be able to do it this way. Which is a lot less code to write... – Houman Oct 26 '09 at 09:44