我有一個WIndows Forms應用程序。我需要一個DataGridView,所以我添加了一個。我假設用戶添加了一些行並按下保存按鈕。DataGridView返回太多列
在這一刻我想保存網格中的所有行。我遍歷這樣的所有行
foreach (DataGridViewRow item in dataGridView.Rows)
{
}
現在的問題。我已經在網格中測試了一行。第一行(我輸入的)正確。然後來到一個無名的行我至今沒有意見。該行中的所有值對於int均爲1,對於字符串爲null。然後出現一行,這對每一列都是空的。編輯: 我可以解釋我想做什麼。我有4個物體的物體。我有這個對象的列表。我希望用戶編輯和manuplates列表和其內的obejcts,
編輯2: 我的問題是不獲取數據。我的問題是,得到的數據不存在。我已經嘗試了4行現在。所以我在網格中填入4行。
我輸入了
1 2 a 1
12 3 b 3
12 4 c 4
13 5 d 5
輸出
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)
您是否將datagridview綁定到任何東西? – w69rdy 2010-07-07 13:22:10
對於DataTable是的 – Markus 2010-07-07 13:23:24
正如@Serkan Hekimoglu所說的,循環遍歷數據表,而不是datagridview。 – w69rdy 2010-07-07 13:31:36