How to open a form with only the type name

2

I have a DataGridView on my form, remembering that it gets the name of the forms from the MySQL database.

I have tried some ways to click on the name of the form in DataGridView and open it, but I did not succeed.

Table examples

Column Name:

id,  
nome - (nome fantasia do formulário) [Empresas],  
slug - (nome real do formulário na aplicação) [frm_empresas]

The idea is to click on the record in DataGridView and open the form, however collecting the name of the form in DataGridView from column slug .

    
asked by anonymous 10.10.2016 / 15:13

1 answer

1

Assuming you know how to get the value of DataGridView , I'll stick to my answer to how to open a form using just the type name.

Reflection solves your problem very well and is not complicated at all. Suppose I want to open the form named Form1 , which is in the AbrindoForms namespace.

Note : You must add the namespace System.Reflection

Dim slugform As string
slugform = "AbrindoForms.Form1"

Dim form = DirectCast(Assembly.GetExecutingAssembly().CreateInstance(slugform), Form)
form.ShowDialog()

Notice that a DirectCast of the return of CreateInstance (which is a object ) is made for type Form . Since all form's inherit from this class, this is quiet and allows you to call native methods of type Form , like the ShowDialog I use in the example.

    
10.10.2016 / 18:04