c# - I've stored form names in a data base. now i want to load forms by using those names -


i've stored form names in data base. want load forms using names. here table structure:

frmid, item_name, formname 

here code:

 private void treeview1_afterselect(object sender, treevieweventargs e) { //treenode node = treeview1.selectednode; string item = convert.tostring(treeview1.selectednode); int index = item.indexof(" "); if (index > 0) item = item.substring(index + 1); //messagebox.show(item); var selectedfrm = menu in dbdata.menus menu.item_name == item select menu; foreach (var pick in selectedfrm.take(1)) { string sel = pick.form_name; assembly asm = typeof(form).assembly; type type = asm.gettype(sel); string df = convert.tostring(type); messagebox.show(df); assemblyname assemname = asm.getname(); messagebox.show(assemname.name); try { form frmchk = (form)activator.createinstance(type); frmchk.show(); } catch (exception) { messagebox.show("error in loading form"); } // messagebox.show(sel); } 

upto assembly asm = typeof(form).assembly; code working properly. how can load form using "formname" in database

this problem, suspect:

assembly asm = typeof(form).assembly; type type = asm.gettype(sel); 

that assembly system.windows.forms assembly - doesn't include your specific forms. use any of forms know in right assembly, instead of form:

// or whatever know about, of course... assembly asm = typeof(loginform).assembly; 

note name still need namespace-qualified name.

another (more flexible) alternative store assembly-qualified name of type can obtain via type.assemblyqualifiedname. can use type.gettype(aqname) - means code still work if split forms across multiple assemblies.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -