代码之家  ›  专栏  ›  技术社区  ›  Markus

DataGridView返回的列太多

  •  0
  • Markus  · 技术社区  · 14 年前

    此时我想保存网格中的所有行。我像那样迭代所有行

    foreach (DataGridViewRow item in dataGridView.Rows)
                {
                }
    

    现在问题来了。我已经测试了它在网格中的一行。第一行(我输入的)正确。然后又来了一排我没料到的。该行中的所有值的int值为1,string值为null。然后是一行,每列都是空的。

    编辑: 我可以解释一下我想做什么吗。我有4个属性的对象。我有这些物品的清单。我希望用户编辑和编辑列表和其中的对象,

    编辑2: 我的问题不是获取数据。我的问题是获取不存在的数据。我已经试过四排了。所以我在网格里排了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)
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Serkan Hekimoglu    14 年前

    为您的数据表dt,dt.AcceptChanges()创建;

        2
  •  1
  •   Denis Palnitsky    14 年前

    这是一个新的行,检查 if (item.IsNewRow) continue;