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 测试但没有用..