cast string to ToolStripMenuItem in vb.net -


i want cast string toolstripmenuitem using directcast function. code is:

   dim parentmenu toolstripmenuitem =         directcast(combobox1.selecteditem, toolstripmenuitem) 

but raise following error

unable cast object of type 'system.string' type 'system.windows.forms.toolstripmenuitem'.

you cannot cast string toolstripmenuitem because of simple fact string is not toolstripmenuitem! directcast function requires kind of relationship (like inheritance) between 2 objects work. means 1 of 2 objects must same type other, or 1 of them must inherit or implement other one.

read more directcast: https://msdn.microsoft.com/en-us/library/7k6y2h6x.aspx

if want done in 1 line do:

dim parentmenu new toolstripmenuitem(combobox1.selecteditem.tostring()) 

you need use .tostring() or cstr() since combobox1.selecteditem returned object.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -