C# – How to delete the row from datagridview

cdatagridviewwinforms

Friends, I'm using datagridview in my windows C# application. We know that When the form with datagridview is loaded a default row is created in the grid. If we type anything in any cell(I've total 6 columns, 2 hidden columns), a new row is created. But if we delete the entry the newly created row is not deleted. In this way we can create as many row we want without keeping any value inside any cell. I want the datagridview to maximum create 2 such rows and when in both the rows, no value is present, the last row to be deleted (so that grid will have 1 row without any data in it). I've tried to remove row in datagridview1_CellValueChanged event, but it's not working. Which event should I use and how can I get the desired functionality? Please help.

Best Answer

Try this:

DataGridView1.Rows.Remove(row);
Related Topic