How to manually add new rows to datagrid
A:
You should not add rows to datagrid. You should add rows to object (collection, datatable) bounded to datagrid.
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Rows.Add(new[]{"John"})
datagrid.DataSource = dt;
//Adding new rows - simply paste this code into (for example) button click event handler
dt.Rows.Add(new[]{"New John"})
//And you should be able to see new row added to grid
Also there are number of commercial grids that supports unbound mode.
Sergey Mirvoda
2009-12-23 09:13:39
I have the same question. but I want to call the DataGrid.InitializingNewItem etc., I want the user to have a button that imitates the user double-click on the new row place-holder in the DataGrid.Please take a look at my question here: http://stackoverflow.com/questions/3860258/manually-cause-the-datagrid-to-create-a-new-item-and-edit-it
Shimmy
2010-10-05 01:15:09