Convert string to ToolStripMenuItem

Posted by Rashedbin under VB.NET on 8/19/2015 | Points: 10 | Views : 1723 | Status : [Member] | Replies : 1
i want to cast a string to ToolStripMenuItem in using DirectCast code is

Dim ParentMenu As ToolStripMenuItem = DirectCast(ComboBox1.SelectedItem, ToolStripMenuItem)

but it raise the following error--- Unable to cast object of type 'System.String' to type 'System.Windows.Forms.ToolStripMenuItem'. please,answer me.


Posted by: Sheonarayan on: 8/19/2015 [Administrator] HonoraryPlatinum | Points: 25

The simple reason for this is that ToolStripMenuItem is not of string type so it is not getting converted. Probably you need to instantiate ToolStripMenuItem by passing the ComboBox1.SelectedItem or ComboBox1.SelectedItem.Value and then try to cast it.


Sheo Narayan

Rashedbin, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response