在通过反射从程序集中加载的表单的“DataGridView”上设置“EventHandler”,会导致禁用所有先前在“DataGridView”上定义的事件处理程序,尽管事件处理程序不相同
我使用下面的代码将程序集加载为“表单”
string FullName = ApplicationPath + @"\DLL\" + DllName + ".dll";
System.Reflection.Assembly assmbly = System.Reflection.Assembly.LoadFrom(FullName);
Type[] contr = assmbly.GetTypes();
if (contr[0].BaseType.FullName == ("System.Windows.Forms.Form"))
{
System.Windows.Forms.Form frm = assmbly.CreateInstance(contr[0].FullName) as Form;
frm.Show();
}
然后我使用下面的代码在从程序集中加载的表单的“DataGridView”上设置一个“事件处理程序”
foreach (Control ThisControl in ThisView.Controls) // ThisView is the same Form loaded from an assembly
{
if (ThisControl.GetType().ToString().Trim() == "System.Windows.Forms.DataGridView")
{
DataGridView ThisGrid = (DataGridView)ThisControl;
ThisGrid.MouseDown += new MouseEventHandler(ThisGrid_MouseDown);
}
}
怎么了?谢谢大家...