B
Bob Shiflett
Greetings,
Using VS 2005 SP1; I created a simple form by dragging and dropping a data
table. I changed it to a details view, so I have a mixture of text boxes,
combo boxes and a check box (no dgv). I want to programatically populate the
controls when the user clicks on the Add New button, so I added the following
event handler:
void MyDataTable_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
int nIndex = int.Parse(this.bindingNavigatorPositionItem.Text);
e.Row.BeginEdit();
e.Row["Col0"] =
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray[0].ToString();
e.Row["Col1"] =
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray[1].ToString();
e.Row["Col2"] =
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray[2].ToString();
...etc...
e.Row.EndEdit();
}
This works surprisingly well; the user can select any row and use it as a
template for the new row. I tried to take this a step further; instead of
setting the columns individually, I tried to use the CopyTo function as
follows:
void MyDataTable_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
int nIndex = int.Parse(this.bindingNavigatorPositionItem.Text);
e.Row.BeginEdit();
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray.CopyTo(e.Row.ItemArray,
0);
e.Row.EndEdit();
}
The code seems to execute, but all my controls are blank, like the CopyTo
did nothing; what am I missing here? Shouldn't this work?
Using VS 2005 SP1; I created a simple form by dragging and dropping a data
table. I changed it to a details view, so I have a mixture of text boxes,
combo boxes and a check box (no dgv). I want to programatically populate the
controls when the user clicks on the Add New button, so I added the following
event handler:
void MyDataTable_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
int nIndex = int.Parse(this.bindingNavigatorPositionItem.Text);
e.Row.BeginEdit();
e.Row["Col0"] =
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray[0].ToString();
e.Row["Col1"] =
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray[1].ToString();
e.Row["Col2"] =
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray[2].ToString();
...etc...
e.Row.EndEdit();
}
This works surprisingly well; the user can select any row and use it as a
template for the new row. I tried to take this a step further; instead of
setting the columns individually, I tried to use the CopyTo function as
follows:
void MyDataTable_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
int nIndex = int.Parse(this.bindingNavigatorPositionItem.Text);
e.Row.BeginEdit();
this.myDataSet.MyDataTable.Rows[nIndex].ItemArray.CopyTo(e.Row.ItemArray,
0);
e.Row.EndEdit();
}
The code seems to execute, but all my controls are blank, like the CopyTo
did nothing; what am I missing here? Shouldn't this work?