private void dgv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int MaxRows = dgv.Rows.Count;
for (int i = 0; i < MaxRows-1; i++)
{
SqlDataAdapter da = new SqlDataAdapter("SELECT CAST(originalPrice * " + (1.00 + (float.Parse(txtMarkUp.Text) / 100.00)).ToString() + " * " + (1.00 + (float.Parse(dgv.Rows[i].Cells[4].Value.ToString()) / 100.00)).ToString() + " AS decimal (8,2)) AS sellingPrice FROM Warehouse WHERE barcode = '" + Convert.ToString(dgv.Rows[i].Cells[2].Value) + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
DataGridViewComboBoxColumn sellingPrice = dgv.Columns["sellingPrice"] as DataGridViewComboBoxColumn;
sellingPrice.DataSource = dt;
sellingPrice.ValueMember = "sellingPrice";
sellingPrice.DisplayMember = "sellingPrice";
dgv.Rows[i].Cells[5].Value = dt.Rows[0].ItemArray.GetValue(0);
dgv.Rows[i].Cells[4].Value = dt.Rows[0].ItemArray.GetValue(2).ToString(); //percent of tax for that category of product
}
}
这段代码运行完美,但只适用于组合框中的一个值... 我需要在不同的行中有不同的值来填充组合框。如何做到这一点? 例如,当第二列的产品更改时,我需要更改第五列的销售价格组合框的值。 非常感谢任何帮助,我几乎没有任何解决方案。谢谢。