Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I copy or duplicate an object

Status
Not open for further replies.

pbb72

Programmer
Mar 27, 2004
38
NO
How do I copy or duplicate an object in .NET?

I've got a big table, where I want to repeat the header row a few time. What I tried is the following:

Code:
TableRow trHead = new TableRow();
TableHeaderCell th = new TableHeaderCell();
th.Text = "blah";
trHead.Cells.Add(th);

TableRow trHeadRepeat1 = trHead;
tbl.Rows.Add(trHeadRepeat1);

// Add a few data rows

TableRow trHeadRepeat2 = trHead;
tbl.Rows.Add(trHeadRepeat2);

// Add more data rows, etc

The result is however that only one header row shows up, at the last location. Apparently I didn't make a *real* copy of the row each time. How should I do this properly?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top