Convert string to ToolStripMenuItem

Posted by Rashedbin under VB.NET on 8/19/2015 | Points: 10 | Views : 976 | Status : [Member] | Replies : 1
i want to cast a string to ToolStripMenuItem in vb.net using DirectCast function.my 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.




Responses

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

Up
0
Down
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.

Thanks


Regards,
Sheo Narayan
http://www.dotnetfunda.com

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

Login to post response