If you have context menu assigned to multiple controls on your form often you will need to identify which control was context menu invoked for. SourceControl property will hold the reference to the control that invoked the context menu. You need to access the SourceControl property on the context menu item rather than the actual menu item. For example if you have Cut, Copy and Paste menu items in your context menu that you call ‘editContext’ then you need to access the SourceControl property on ‘editContext’ item. You can always easily get to that from item click event handler by access the Parent property of clicked item.

C# Example:

private void ItemClick(object sender, EventArgs e)
{
    BaseItem item = sender as BaseItem;
 
    if (item.Name == ”itemCopy” || item.Name == ”itemPaste” || item.Name == ”itemCut”)
    {
        ButtonItem ctx = item.Parent as ButtonItem;
 
        // Go to the top most parent since that is our editContext menu.
        // This code will be executed if we have multi-level context menu.
 
        while (ctx.Parent != null)
           ctx = ctx.Parent;
 
        // ctx.SourceControl will now hold the reference
        // to the control that invoked context menu.
 
    }
}

VB Example:

Private Sub ItemClick(sender As Object, e As EventArgs)
    Dim item As BaseItem = TryCast(sender, BaseItem)
 
    If item.Name = itemCopy OrElse item.Name = itemPaste OrElse item.Name = itemCut Then
        Dim ctx As ButtonItem = TryCast(item.Parent, ButtonItem)
 
        ' Go to the top most parent since that is our editContext menu.
        ' This code will be executed if we have multi-level context menu.

        While ctx.Parent IsNot Nothing
            ctx = ctx.Parent
        End While
 
        ' ctx.SourceControl will now hold the reference
        ' to the control that invoked context menu.

    End If
End Sub

Related posts:

  1. How to Create Context Menus
  2. How to set ColorScheme for context menus
  3. How to add any control to menu, toolbar and other DotNetBar controls
  4. How to display any control on popup
  5. How to attach Click event handler to Clear or Today buttons in Month Calendar displayed by DateTimeInput control