无法看到除最后一行之外的所有行

时间:2012-11-19 07:42:01

标签: c# data-binding datagridview

while (dr2.Read())
        {               
            dataGridViewEx1["Sno", dataGridViewEx1.RowCount-1].Value = sno;
            dataGridViewEx1["Prod_Code", dataGridViewEx1.RowCount-1].Value = dr2["Code"].ToString();
            dataGridViewEx1["Description", dataGridViewEx1.RowCount-1 ].Value = dr2["Desc"].ToString();
            dataGridViewEx1["Qty", dataGridViewEx1.RowCount-1 ].Value = 0;
            DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)dataGridViewEx1.Rows[dataGridViewEx1.RowCount - 1].Cells["UOM"];
            cell.Value = dr2["UOM1"].ToString();
            dataGridViewEx1["OnHand", dataGridViewEx1.RowCount - 1].Value = dr2["Weight"].ToString();
            dataGridViewEx1["uom1", dataGridViewEx1.RowCount - 1].Value = dr2["UOM"].ToString();
            dataGridViewEx1["UPrice", dataGridViewEx1.RowCount - 1].Value = dr2["Price"].ToString();
            dataGridViewEx1.Rows.Add(1);
            //dataGridViewEx1.CommitEdit(DataGridViewDataErrorContexts.Commit);

        }
        dr2.Close();

此代码仅添加最后一行。为什么它不添加以前的行.....我甚至测试了commitedit但没有用..

1 个答案:

答案 0 :(得分:0)

您每次只会插入原始广告:dataGridViewEx1.RowCount-1