I have a Windows Forms Application. I needed a DataGridView so I added one. I assume that the user adds some rows and press a save button.
At this moment I want to save all rows in the grid. I iterate through all rows like that
foreach (DataGridViewRow item in dataGridView.Rows)
{
}
Now the problem. I have tested it with one row in the grid. The first row (which I typed in) comes correctly. then comes another row which I didn't expect. All values in that row have the value 1 for int and null for string. and then comes a row this just null for every column.
EDIT: May I explain what I wanted to do. I have objects with 4 properties. I have list of this objects. And I want that the user edits and manipulates that list and the objects inside it,
EDIT2: My problem is not to get the Data. My problem is that is get Data which does not exist. I have tried it with 4 rows now. So I filed in 4 rows in the grid.
my input was
1 2 a 1
12 3 b 3
12 4 c 4
13 5 d 5
output is
1 2 a 1
1 1 null 1 (why the heck is that one here)
12 3 b 3
12 4 c 4
13 5 d 5
null null null null (this row I could live with because I know where it comes from)
make for your DataTable dt, dt.AcceptChanges(); and start loop in foreach(DataRow dr in dt.Rows)