Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:04:44+00:00 2026-06-01T04:04:44+00:00

A ListBox and a ContextMenu are created dynamicaly. The ListBox has some items. How

  • 0

A ListBox and a ContextMenu are created dynamicaly. The ListBox has some items.
How do I know the ListBoxItem Text that right mouse button clicked on?

private void Init2()
{ 
    ContextMenu contextMenu = new ContextMenu();

    MenuItem menuItemOpen = new MenuItem();
    menuItemOpen.Click += new RoutedEventHandler(menuItemOpen_Click);
    contextMenu.Items.Add(menuItemOpen);
    listBox1.ContextMenu = contextMenu;
}
void menuItemOpen_Click(object sender, RoutedEventArgs e)
{
    //How do I know the listItem text that  right mouse button clicked on?
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:04:45+00:00Added an answer on June 1, 2026 at 4:04 am

    When you right click, you actually also select. So that means you can just do:

        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            string selectedListBoxItemText = ((ListBoxItem)listBox1.SelectedItem).Content.ToString());
    
            // do your thing
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListBox that has a style defined for ListBoxItems. Inside this style,
I have a Contextmenu with a ListBox inside. Whenever I right click my control
I'm trying to sho a contextmenu on right-click on an item in a listbox.
I have a ListBox with items, and have assigned a ContextMenu to it with
I have a ListBox that contains a number of User items that are DataTemplate
I have a ListBox, that's bound to an ObservableCollection . Each ListBoxItem is displayed
I have a WPF ListBox that typically shows 4 or 5 items. For my
I'm trying to add a ContextMenu to items in a ListBox in WPF; <ListBox.ItemTemplate>
I have a listbox whose listboxitem contains, among other things, a button, as follows:
First take a look at my code: <ListBox ItemsSource={Binding} SelectionMode=Multiple ItemTemplate={StaticResource ContactTemplate}> <ListBox.ContextMenu> <ContextMenu>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.