【毕设】Contorl.Invoke(delegateMethod,object[])遇到的问题
在添加销售订单的时候,在子窗口添加完购买的商品信息后。原理是将新的商品信息添加到string[]里,再使用invoke()方法将string[]作为参数传到父窗口对商品进行 汇总。但是在代码执行的时候会出现编译错误。

源代码:
public void addProduct(string[] product) { AddProductDelegate del = delegate (string[] strs) { DataGridViewRow dr = new DataGridViewRow(); dr.CreateCells(dgvProduct); dr.Cells[0].Value = strs[0]; dr.Cells[1].Value = strs[1]; dr.Cells[2].Value = strs[2]; dr.Cells[3].Value = strs[3]; dr.Cells[4].Value = strs[4]; dr.Cells[5].Value = strs[5]; dr.Cells[6].Value = strs[6]; dgvProduct.Rows.Add(dr); }; dgvProduct.Invoke(del, product); }
再查阅MSDN后,将代码改成:
dgvProduct.Invoke(del, new object[] { product });
编译通过,达到效果。
MSDN:https://msdn.microsoft.com/zh-cn/library/a1hetckb(v=vs.110).aspx
浙公网安备 33010602011771号