locked
Disable New Row on DataGrid RRS feed

  • Question

  • Is there any way to disable the ability to create a new row at the bottom of a datagrid?  The row marked as "*" appears automatically and I want to disable so I can programatically control inserting of new rows.

     

    Thanks

    Tuesday, October 10, 2006 9:19 PM

All replies

  • Set the "AllowUserToAddRows" property to false of the datagridview either in code or in the datagridview properties. This will prevent the user from adding rows. To add rows, you would have to add the rows in the datasource (Dataset for example) and rebind the datagridview to reflect/show the changes
    Tuesday, October 10, 2006 9:55 PM
  • I am using VS 2003 and DataGrids.  I dont see that as a property option.

     

    Thanks

    Tuesday, October 10, 2006 10:05 PM
  • ok, its different for VS2003 then...

    The only closest thing I've come to is making the ReadOnly property to true, this will however not allow the user to edit or delete rows but does stop them from adding anything to it. Again, if you need to add rows then you need to add them to the datasource and rebind it to the datagrid.

    I'll see what else I can find!

    Tuesday, October 10, 2006 10:13 PM
  • If the new row is showing up, then your datasource is an IBindingList (a DataView if you are binding to a DataTable). You need to set the AllowNew property of the datasource to false. For example, if you are binding to the DataTable myDataTable, then set "myDataTable.DefaultView.AllowNew = false;".
    Wednesday, October 11, 2006 2:33 AM
  • Thanks a lot David !!

    There's a lot of help on DataGridView and it has fairly simpler properties and easy to find and set them but DataGrid control doesn't expose such property.

    Thanks again for this valuable answer !!


    Thursday, August 20, 2020 1:06 PM