0

I'm trying to access the TAG of the parent control (a dynamic button) of the context menu strip sub item.

In my scenario, No. of buttons added dynamically on a form and a ContextMenuStrip named CMS is attached with each dynamic button added.

BTN.ContextMenuStrip = CMS

here is my context menu strip design

enter image description here

Tag of the parent button should be return by clicking All. But I'm always getting NULL.

Here is my code.

Dim child As ToolStripMenuItem = sender 'Sub item (text=All)
Dim parent As ToolStripItem = child.OwnerItem 'Parent Item (text=Check)
Dim CMStrip As ContextMenuStrip = parent.Owner 'Context menu strip
MsgBox(CMS.SourceControl.Text) 'Source control should be button but it's null.

enter image description here

I'm using .NET Framework 2.0.

Muhammad Saqib
  • 2,185
  • 3
  • 35
  • 48
  • 2
    I answered something very similar quite recently http://stackoverflow.com/questions/37700548/vb-net-get-the-control-that-is-used-to-show-the-contextmenu-strip/37701471#37701471 – Robin Mackenzie Jun 08 '16 at 13:36
  • 1
    @Robin Thanks a lot, So it's a bug. I have tried the alternative method you have suggested and is working fine. +1. – Muhammad Saqib Jun 08 '16 at 13:49

0 Answers0