Different ComboBox values in DataGridView in different rows

    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
        }
    }

This code is working perfectly but only for one values in combobox... I need different values in different rows for the combobox. How can I do that? In example when in column 2 product is changed, I need it to change the values of column 5 which is combobox with the selling prices. Any help would be appreciated, I have almost no solution for this in my mind. Thanks.

5
задан dex 2 May 2011 в 10:15
поделиться