1

I have datagridview on my form and I want to allow user to add new row only if he fills up all cells in the previous one.

How I can do it?

Saleh
  • 2,657
  • 12
  • 46
  • 73
  • 1
    possible duplicate of [How to add new row to datagridview only after specific cells of the row above are filled?](http://stackoverflow.com/questions/5126523/how-to-add-new-row-to-datagridview-only-after-specific-cells-of-the-row-above-are) – Cody Gray - on strike Mar 23 '11 at 00:03
  • @Cody Gray: the code is not working as I need – Saleh Mar 23 '11 at 00:10
  • That's not very helpful. I can't very well tell you how to fix something if you don't tell me what's wrong with it. You really need to put more effort into your questions than this. – Cody Gray - on strike Mar 23 '11 at 00:14
  • @Cody Gray: What I want is to check every cell in the row and if there is one empty, display a message for the user for example to tell him to fill the empty cells and all this will happen when the user try to insert new row in the datagridview – Saleh Mar 23 '11 at 00:17
  • Yup, the answer to that question is how to do that. You'll have to do some thinking on your own. For example, it doesn't already have the code written to show a message box. But your question isn't nearly detailed enough for anyone answering it to know that, either. – Cody Gray - on strike Mar 23 '11 at 00:19

2 Answers2

0

if your datagridview has no checkboxes or custom-made columns, you can just check at every step if all your fields from your last row are not null or empty, then make the AllowUserToAddRows = true

example:

bool all_fields_completed=true;
for(int i=0;i<mydatagrid.Columns.count;i++)
if(String.IsNullorEmpty(mydatagrid.Rows[mydatagrid.Rows.Count-1].Cells[i].Value.ToString()))
   all_fields_completed=false;

if (all_fields_completed==true) mydatagrid.AllowUserToAddRows = true;
-1

Click on your Datagridview --> Click Datagridview task --> and Check Enable Adding.

Regards

Crimsonland
  • 2,194
  • 3
  • 24
  • 42