Disable New Row on DataGrid RRS feed

  • 問題

  • 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.



    2006年10月10日 下午 09:19


  • 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
    2006年10月10日 下午 09:55
  • I am using VS 2003 and DataGrids.  I dont see that as a property option.



    2006年10月10日 下午 10:05
  • 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!

    2006年10月10日 下午 10:13
  • 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;".
    2006年10月11日 上午 02:33
  • 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 !!

    2020年8月20日 下午 01:06