Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pass parameter to form constructor
Message
From
26/08/2007 12:41:46
 
 
To
26/08/2007 10:06:07
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01250488
Message ID:
01250500
Views:
9
As I mentioned elsewhere, I use MyAssembly.CreateInstance() instead of Activator.CreateInstance(), but it doesn't really matter. You say the call to the parameter-less constructor works, so I guess you've got that part figured out ok.

As far as passing the parameters, what you've got looks ok ... are you sure the parameters are in the correct order and are of the correct type? Something like the Enum might trip you up (depending on whether your Form expects an Enum value to be passed to it or simply an int).

It really shouldn't matter, but just for the heck of it, have you tried creating the object[] first and using that in the call instead? Like this:
object[] parms = new object[3];
object[0] = JK.Payment.Enums.TxnType.Sale;
object[1] = salesBO.SaleNo;
object[2] = salesBO.Total;
loForm = (PaymentForm) Activator.CreateInstance(Type.GetType("JK.Payment.UI.Windows.Forms.PaymentForm"), parms);
~~Bonnie




>Hi,
>I have problem to pass parameter to form constructor using Activator.CreateInstance().
>
>I have code below,
>
>Hi,
>I am facing the same problem.
>
>I tried the code below.
>
>
>            //Workign OK
>            Payment.UI.Windows.Forms.PaymentForm loForm = new PaymentForm(new object[]
>                { JK.Payment.Enums.TxnType.Sale, salesBO.SaleNo, salesBO.Total });
>
>            loForm.ShowDialog();
>
>            loForm.Dispose();
>
>            //Workign OK
>            loForm = (PaymentForm)Activator.CreateInstance(Type.GetType("JK.Payment.UI.Windows.Forms.PaymentForm"));
>
>            loForm.ShowDialog();
>
>            loForm.Dispose();
>
>            //NOT Workign OK
>            loForm = (PaymentForm) Activator.CreateInstance(Type.GetType("JK.Payment.UI.Windows.Forms.PaymentForm"),
>                                                            new object[]
>                                                                {
>                                                                    JK.Payment.Enums.TxnType.Sale, salesBO.SaleNo,
>                                                                    salesBO.Total
>                                                                });
>
>            loForm.ShowDialog();
>            loForm.Dispose();
>
>
>Please advice
>
>Thank you
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform