Ive faced with problem where I cant manage to figure out how to convert a string into a form object. Im currently working on developing a form explorer using vb.net. My form explorer has 2 panes, left pane is a tree that shows all the form names, and right pane will be the place where the selected form will be shown. Currently, Im using hard code method to show the selected form on the right pane.
E.g. When the user select on particular node, my code behind will look like this;
Select Case Trim(SelectedNode)
Case " Registration "
Dim frmActive As FrmRegist = New FrmRegist ()
Dim frmActive As FrmRenew = New FrmRenew ()
IMHO, its not a good practice to code in this way, for me its not dynamic enough and modification on coding is needed every time a form is added in. So I think of keeping all the forms name in a table. So if any forms added in future, just need to add the info into table no need to modify the coding again.
The table format is basically like below: -
Node Caption(see by user) OriginalFormName
**Both columns is define under varchar type. (I wish to stored the OriginalFormName
column under form or object type, but those type are not supported in sql)
Here, when a user select on particular node, Ill compare the selected node name with the node caption value in the table, if match then load the form. The code is look like below:
**This is the part where problem occur.
If match then
StrOriginalFormName= Selected OriginalFormName FrmRegist
frmSelectedForm = CType(StrOriginalFormName, Form)
Dim frmActive As frmSelectedForm = New frmSelectedForm ()
The problem occurred when I try to convert a string (FrmRegist) into Form type.
The message shown:- Value of type 'String' cannot be converted to 'System.Windows.Forms.Form'.
May I know how to solve this problem? Or is there any other way to fulfill my concept? Thanx in advance.