[ad_1]
I want to add an order in my inventory management system by selecting a product from a datagridview.
This is my Products Grid view code :
int flag = 0;
private void ProductsGV_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
product = ProductsGV.Rows[e.RowIndex].Cells[1].Value.ToString();
uprice = Convert.ToInt32(ProductsGV.Rows[e.RowIndex].Cells[3].Value.ToString());
flag = 1;
}
And This is my add button code :
private void button1_Click(object sender, EventArgs e)
{
if (QteTb.Text == "")
MessageBox.Show("Entrez la quantité de produit");
else if (flag == 0)
MessageBox.Show("Choisir un produit");
else
{
num = num + 1;
qty = Convert.ToInt32(QteTb.Text);
totprice = qty * uprice;
DataTable table = new DataTable();
//table.Columns.Add(num, product, qty, uprice, totprice);
table.Rows.Add(num, product, qty, uprice, totprice);
OrderGV.DataSource = table;
//flag = 0;
}
}
When I try to add an order I get This error : “The input table is longer than the number of columns in this table.”
[ad_2]