Are you shure about that? Because the code works fine for me. Here's one
example:
----------------------
private void Page_Load(objec t sender, System.EventArg s e)
{
DataTable _dt = new DataTable();
_dt.Columns.Add ("col1", typeof(int));
_dt.Columns.Add ("col2", typeof(string)) ;
_dt.Columns.Add ("col3", typeof(string)) ;
DataRow dr = _dt.NewRow();
dr[0] = 1;
dr[1] = "some text";
dr[2] = "one";
DataRow drCopy = CopyRow(dr);
drCopy[0] = 2;
drCopy[2] = "two";
_dt.Rows.Add(dr );
_dt.Rows.Add(dr Copy);
DataGrid1.DataS ource = _dt;
DataGrid1.DataB ind();
}
private DataRow CopyRow(DataRow dr)
{
DataRow drCopy = dr.Table.NewRow ();
for(int i=0;i<dr.Table. Columns.Count;i ++)
drCopy[i] = dr[i];
return drCopy;
}
----------------------------------
The result for the grid is this:
col1 col2 col3
1 some text one
2 some text two
----------------------------------
Marius
"Eliyahu Goldin" <re************ *@monarchmed.co m> wrote in message
news:et******** ******@TK2MSFTN GP15.phx.gbl...
Marius,
dr[i] returns a reference to the cell. I am afraid in your solution dr and
drCopy will share the same set of cells.
Eliyahu
"Marius Tennes Krogh" <ma***@online.n o> wrote in message
news:uH******** *****@tk2msftng p13.phx.gbl...
"JIM.H." <JI**@discussio ns.microsoft.co m> wrote in message
news:AA******** *************** ***********@mic rosoft.com... Hello
I have;
DataRow dr= dataSet11.myTab le.NewRow();
And I am filling the fields of this datarow. Now I need to create a copy
of
this row as drCopy and change a few fields and add both to the dataset,
how
can I do this?
Thanks,
You can create your own little method for copying a row:
private DataRow CopyRow(DataRow dr)
{
DataRow drCopy = dr.Table.NewRow ();
for(int i=0;i<dr.Table. Columns.Count;i ++)
drCopy[i] = dr[i];
return drCopy;
}
Marius