Insert new Row DataGrid WindowsForm

  • Thread starter Thread starter Steven M
  • Start date Start date
S

Steven M

Hello group
I have a trouble.

When I going to write a new row in a DataGrid, I have some columns
that must to be write with a especial value.

How do I can do it?

Thanks a lot

Steven
 
I dont really understand what you are trying to say here... perhaps you can
rephrase the question?
R. Thomas
 
Hi Steven,

If you mean WinForms DataGrid, it always operates in the bound mode.
Therefore, you need to add a new row to the grid's datasource - most likely
a DataTable. If this is what you want, just add a new row to the datasource
and populate the row with the initial values.
 
Hello!!!

When you link the DataGrid control with a DataSet let you create new
rows. How can I put default values on those new rows ?

thanks a lot!!!!
 
hi steven,
When you say how to put default values on those rows? do you already have
rows? If yes, just loop thru the dg and place a default value one by one...
For Each item as DaraGridItem in myDg.Items
'put a loop for cells here and assign default values...
Next
Hth
R. Thomas
 
Hi R.Thomas!!!
The problem is do that in a DataGrid in Windows Forms.
Do you have any idea?

Thanks!!!

Steven
 
Steven,

Here's an example from MSDN (which I have amended a little bit) adding 10
new pre-populated rows to a DataTable:

// Assuming the grid is bound to myDataSet and the DataMember value is
"Customers"
// Something like dataGrid.SetDataBinding(myDataSet, "Customers");

DataTable workTable = myDataSet.Tables["Customers"];
DataRow workRow;

for (int i = 0; i <= 9; i++)
{
workRow = workTable.NewRow();
workRow["CustomerID"] = i;
workRow["CustomerName"] = "CustName" + i.ToString();
workTable.Rows.Add(workRow);
}
 
Back
Top