我正在尝试使用C#Excel加载项填充带有100个组合框的Excel工作表。我的问题是我需要创建一个Genering过程CmdBtn_Click(),它将由组合框的每个实例调用并传递它们的值和名称。换句话说,我需要参数驱动的程序,它将由适当的事件调用。有人可以建议如何在C#中做到这一点吗?
for (int i = 1; i < col + 1; i++)
{
var comboRange = currentSheet.Cells[2, i];
var cmb_Column = (Excel.Shape)currentSheet.Shapes.AddOLEObject("Forms.ComboBox.1",
Type.Missing,
false,
false,
Type.Missing,
Type.Missing,
Type.Missing,
Convert.ToInt32(comboRange.Left),
Convert.ToInt32(comboRange.Top),
Convert.ToInt32(comboRange.Width),
Convert.ToInt32(comboRange.Height));
cmb_Column.Name = "cmb_Column" + i;
Excel.OLEObject oleComboBox = (Excel.OLEObject)cmb_Column.DrawingObject;
cb = Invoker.PropertyGet(oleComboBox, "Object") as MSForms.ComboBox;
cb.AddItem("Test1");
cb.Change += new MSForms.MdcComboEvents_ChangeEventHandler(CmdBtn_Click);
}
private void CmdBtn_Click()
{
// Get the Change value of combobox as well as its name
}