views:

179

answers:

2

Hello,

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?

Many Thanks, Kave

+1  A: 

The answer supplied here by lagerdalek should work for you...

http://stackoverflow.com/questions/78536/cloning-objects-in-c

Steve Dignan
A: 

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
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...
Kave