我有一个4-5列的DataGridView
DataGridView是可编辑的
当我在参考列中输入一个值时,它会立即从mysql数据库填充其他单元格中的其他值
但是当我进入下一行并且我想在参考单元格中添加另一个值然后它将像第一个那样填充另一个时,它没有做到这一点...
这就是我试过的......
private void TAB_Credit_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
if (TAB_Credit.Columns[e.ColumnIndex].Name == "Reference")
{
string cmdText = @"SELECT * FROM tb_ajout_articles
WHERE Reference=@ref";
MySqlDataAdapter sa = new MySqlDataAdapter(cmdText, MyConnexion);
sa.SelectCommand.Parameters.Add("@ref", MySqlDbType.VarChar).Value =
TAB_Credit.Rows[e.RowIndex].Cells["Reference"].Value.ToString();
DataTable dt2 = new DataTable();
sa.Fill(dt);
if (dt.Rows.Count == 1)
{
TXT_Stock.Text = dt.Rows[0]["Quantite"].ToString();
//double value = (double)TAB_Credit.Rows[e.RowIndex].Cells["Quantite"].Value * (double)TAB_Credit.Rows[e.RowIndex].Cells["Prix_Unitaire"].Value;
TAB_Credit.Rows[e.RowIndex].Cells["Designation"].Value = dt.Rows[0]["Designation"].ToString();
TAB_Credit.Rows[e.RowIndex].Cells["Quantite"].Value = dt.Rows[0]["Quantite"].ToString();
TAB_Credit.Rows[e.RowIndex].Cells["Prix_Unitaire"].Value = dt.Rows[0]["Prix_Unitaire"].ToString();
TAB_Credit["Total", e.RowIndex].Value =
Convert.ToString(
Convert.ToInt32(TAB_Credit["Quantite", e.RowIndex].Value) *
Convert.ToInt32(TAB_Credit["Prix_Unitaire", e.RowIndex].Value));
//TAB_Credit.Rows[e.RowIndex].Cells["Total"].Value = value.ToString();
TXT_Brut.Text = TAB_Credit["Total", e.RowIndex].Value.ToString();
}
}
if (TAB_Credit.CurrentCell.ColumnIndex == 6)
{
if (Convert.ToInt32(TAB_Credit.Rows[e.RowIndex].Cells["Quantite"].Value) > Convert.ToInt32(TXT_Stock.Text))
{
MessageBox.Show("Stock finished");
TAB_Credit.Rows[e.RowIndex].Cells["Quantite"].Value = dt.Rows[0]["Quantite"].ToString();
}
else
{
TAB_Credit["Total", e.RowIndex].Value =
Convert.ToString(
Convert.ToInt32(TAB_Credit["Quantite", e.RowIndex].Value) *
Convert.ToInt32(TAB_Credit["Prix_Unitaire", e.RowIndex].Value));
TXT_Brut.Text = TAB_Credit["Total", e.RowIndex].Value.ToString();
}
}
}