I'm trying to get the source control name of my context menu. It works fine when you are casting ToolStripMenuItem and ContextMenuStrip, but I have one drop down ToolStripMenuItem too and It doesn't work same. I tried different approaches using casting ToolStripDropDownItem, ToolStripDropdown, ToolStripMenuItem but I'm allways getting "Object reference not set to an instance of an object." error. A few tries here (both same errors):
Private Sub MicrosoftWordToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MicrosoftWordToolStripMenuItem.Click
'Dim BtnbWord As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
'Dim BtnNew As ToolStripMenuItem = CType(BtnWord.OwnerItem, ToolStripMenuItem)
'Dim Kontexst_M As ContextMenuStrip = CType(BtnNew.Owner, ContextMenuStrip)
Dim BtnWord As ToolStripDropDownItem = CType(sender, ToolStripDropDownItem)
Dim BtnNew As ToolStripDropDown = CType(BtnWord.Owner, ToolStripDropDown)
Dim Kontext_M As ContextMenuStrip = CType(BtnNew.OwnerItem.Owner, ContextMenuStrip)
'I need source control name to handle my click event of this toolstrip item
If Kontext_M.SourceControl.Name= "Listview1" then
Msgbox("Listview1")
End If
Any ideas on how I could get source control name ?...In case you are wondering, I need this to handle right click for creating Word documents: