I find it hard to believe this hasn’t been asked before, but it doesn’t appear like it has been and my Google searches have all been for naught.
Can I set a maximum number of rows that a DataGridView will allow a user to add? (Like after adding the 10th row it will no longer display the ‘new row’ row?).
There is no direct property to do this, but you should be able to accomplish this pretty easily using a combination of the
AllowUserToAddRowsproperty, and theUserAddedRowevent.The general idea is to add an event handler to check the number of rows against the Maximum Allowed, and then set
AllowUserToAddRows = falseYou will also want to handle when a user deletes a row to make sure that you allow them to add rows again.
Hope this helps
Cheers,
Josh