There is no direct property for this, but you should easily accomplish this with a combination of the AllowUserToAddRows property, and UserAddedRow .
The general idea is to add an event handler to check the number of rows in the Maximum allowed , and then set AllowUserToAddRows = false
public partial class frmGridWithRowLimit : Form { public Int32 MaxRows { get; set; } public frmGridWithRowLimit() { MaxRows = 10; InitializeComponent(); dgRowLimit.UserAddedRow += dgRowLimit_RowCountChanged; dgRowLimit.UserDeletedRow += dgRowLimit_RowCountChanged; } private void dgRowLimit_RowCountChanged(object sender, EventArgs e) { CheckRowCount(); } private void CheckRowCount() { if (dgRowLimit.Rows != null && dgRowLimit.Rows.Count > MaxRows) { dgRowLimit.AllowUserToAddRows = false; } else if (!dgRowLimit.AllowUserToAddRows) { dgRowLimit.AllowUserToAddRows = true; } } }
You will also want to process when the user deletes the row to make sure that you allow them to add the rows again.
Hope this helps
Cheers, Josh
Josh
source share