开发者

DataGridView returns too many Columns

开发者 https://www.devze.com 2023-01-06 12:12 出处:网络
I have a WIndows Forms Application. I needed a DataGridView so i added one. I asume that the user adds some rows and press a save button.

I have a WIndows Forms Application. I needed a DataGridView so i added one. I asume 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 trough all rows like that

foreach (Dat开发者_运维百科aGridViewRow 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 a nother row wich i didnt accpected. 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 propreties. I have list of this objects. And i want that the user edits and manuplates that list and the obejcts inside it,

EDIT2: My problem is not to get the Data. My problem is that is get Data which not exists. 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 cause i know where it comes from)


make for your DataTable dt, dt.AcceptChanges(); and start loop in foreach(DataRow dr in dt.Rows)


It is a new row, check for if (item.IsNewRow) continue;

0

精彩评论

暂无评论...
验证码 换一张
取 消