![]() | ![]() |
|
|||||||
| Notices |
![]() |
| Thread Tools | Display Modes |
| #1 | |
| Guest Posts: n/a | Activator.CreateInstance problem I have added a method to my main form that is generic and will open a window given the window name as a string. Unfortunatley, it fails... Here is the method: private void OpenWindow(string asFormName) { foreach (Form f in this.MdiChildren) { if (asFormName == f.GetType().ToString()) { f.Activate(); return; } } Form loForm = (Form)Activator.CreateInstance(Type.GetType(asForm Name)); loForm.MdiParent = this; loForm.Show(); } I call the method: OpenWindow("fornname"); This line fails: Form loForm = (Form)Activator.CreateInstance(Type.GetType(asForm Name)); I get: value cannot be null. Any why I am getting null? Thanks! |
|
| #2 | |
| Guest Posts: n/a | Re: Activator.CreateInstance problem >Any why I am getting null? Type.GetType returns null if it can't find the type ("fornname" in this case). Maybe you've misspelled the type name, or you're missing the namespace. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org | Please reply only to the newsgroup. |
|
| #3 | |
| Guest Posts: n/a | Re: Activator.CreateInstance problem On Dec 10, 3:45 pm, Mattias Sjögren <> wrote: > >Any why I am getting null? > > Type.GetType returns null if it can't find the type ("fornname" in > this case). Maybe you've misspelled the type name, or you're missing > the namespace. > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/| > Please reply only to the newsgroup. It's odd. I verified that the form name is correct. I had not considered it a namespace issue but will take a look. Thanks. |
|
| #4 | |
| Guest Posts: n/a | Re: Activator.CreateInstance problem On Dec 10, 3:45 pm, Mattias Sjögren <> wrote: > >Any why I am getting null? > > Type.GetType returns null if it can't find the type ("fornname" in > this case). Maybe you've misspelled the type name, or you're missing > the namespace. > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.orghttp://www.msjogren.net/dotnet/| > Please reply only to the newsgroup. Thanks, yes, I needed to affix my namespace info before the form name. |
|
![]() |
| Thread Tools | |
| Display Modes | |
< Home - Windows Help - MS Office Help - Hardware Support >
| New To Site? | Need Help? |