3

in my DataGridView I click on a new row, then new empty row appears at the bottom, it is standard behaviour and there is no problem. So I fill the row and click on the last empty row and here is the problem, the row I just filled disappears. Cells in datagridview are of different types textbox, datagridviewcombobox, date, int. I catch DataError event and there is no error message.

Thats the way I set the data source DataGridView.DataSource=dataTable;

I can not find the reason why this happens. I found that one of the reasons could be because entered data are not valid but as far as I am convinced this should not be my case, but maybe I am wrong.

David Hall
  • 32,624
  • 10
  • 90
  • 127
pesaak
  • 131
  • 2
  • 10
  • I just solved it myself and I hope it will help somebody else because I did not find many references concerning this. Finally it really was a problem of data entered into new row. They was correctly entered so there was no error message BUT there was some columns missing and that was a reason why the newly entered row disappeared. So I used event DefaultValuesNeeded, entered all 13 columns, and it works now as expected, I just must tune now which columns to enter by user and which by code. Best regards – pesaak Jun 16 '11 at 07:41
  • 2
    Should have added this as an answer! – tzup Jun 16 '11 at 07:56
  • I can not mark my questions as answer... – pesaak Jun 20 '11 at 21:07
  • Obviously not :) ...but you could write an answer to your question and mark that as the accepted answer. (+ you get more rep when voted up) – tzup Jun 21 '11 at 05:02

1 Answers1

4

I just solved it myself and I hope it will help somebody else because I did not find many references concerning this.

Finally it really was a problem of data entered into new row. They was correctly entered so there was no error message BUT there was some columns missing (I mean columns that are not visible to the user) and that was a reason why the newly entered row disappeared. So I used event DefaultValuesNeeded, entered all 13 columns, and it works now as expected, I just must tune now which columns to enter by user and which by code.

Best regards

pesaak
  • 131
  • 2
  • 10
  • Thanks for the hint - here is a little additional note on what to enter in the function body, for example: `e.Row.Cells["Region"].Value = "WA";` as of http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.defaultvaluesneeded.aspx – acme Apr 27 '12 at 09:52
  • Copy&Pasted from deleted "answer" of [Steve Long](http://stackoverflow.com/users/1824497/steve-long): _" thank you so much for posting that solution. I was just experiencing that problem and couldn't figure out why my new row was disappearing as it had been previously working. The problem was that I added a column and was not handling the new column's New value needed. The indexes changed too and I had to make them correct."_ – Tim Schmelter Aug 04 '14 at 11:45