why not work like in example ?

silvestri silvestri 1 Reputation point
2021-01-20T12:34:17.277+00:00

Hi guys i try to run this simple example but VS2019 with Net 4.8 return me this error https://learn.microsoft.com/it-it/dotnet/api/system.windows.forms.toolstripitemclickedeventargs.clickeditem?view=net-5.0# private void ToolStrip1_ItemClicked(Object sender, ToolStripItemClickedEventArgs e) { System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder(); messageBoxCS.AppendFormat("{0} = {1}", "ClickedItem", e.ClickedItem ); messageBoxCS.AppendLine(); MessageBox.Show(messageBoxCS.ToString(), "ItemClicked Event" ); } Severity Code Description Project File Line Suppression State Error CS1061 'EventArgs' does not contain a definition for 'ClickedItem' and no accessible extension method 'ClickedItem' accepting a first argument of type 'EventArgs' could be found (are you missing a using directive or an assembly reference?) ControllerH C:\Users\stefano\source\repos\ControllerH\ControllerH\Form1.cs 28 Active thanks at all

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,275 questions
{count} votes

6 answers

Sort by: Most helpful
  1. WayneAKing 4,921 Reputation points
    2021-01-20T22:45:11.29+00:00

    'EventArgs' does not contain a definition for 'ClickedItem'
    and no accessible extension method 'ClickedItem' accepting
    a first argument of type 'EventArgs' could be found

    Change this line:

    private void ninjaTraderToolStripMenuItem_Click(object sender, EventArgs e)
    

    to this:

    private void ninjaTraderToolStripMenuItem_Click(object sender, ToolStripItemClickedEventArgs e)
    
    • Wayne
    1 person found this answer helpful.

  2. Viorel 112.5K Reputation points
    2021-01-20T15:45:54.95+00:00

    It seems to work in case of Windows Forms. Make sure that you add the handler for Toolstrip, not for some item. (Just double-click the Toolstrip to add the handler).

    Maybe show your real code and other details.

    0 comments No comments

  3. Karen Payne MVP 35,036 Reputation points
    2021-01-20T16:07:49.183+00:00

    Make sure to have the following using statements

    using System.Windows.Forms;  
    using System.Text;  
    

    58803-11111111111.png

    0 comments No comments

  4. silvestri silvestri 1 Reputation point
    2021-01-20T17:20:21.72+00:00

    i did do the example

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace ControllerH
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void fileToolStripMenuItem_Click(object sender, EventArgs e)
            {
    
            }
    
            private void ninjaTraderToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ///*
                System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
                messageBoxCS.AppendFormat("{0} = {1}", "ClickedItem", e.ClickedItem);
                messageBoxCS.AppendLine();
                MessageBox.Show(messageBoxCS.ToString(), "ItemClicked Event");
                //*/
                //MessageBox.Show("de made ");
            }
        }
    }
    
    0 comments No comments

  5. Timon Yang-MSFT 9,576 Reputation points
    2021-01-22T08:00:39.34+00:00

    I think you may confuse ToolStrip.ItemClicked event and ToolStripItem.Click event.
    You need to use the ToolStrip.ItemClicked event, but based on the current information, you seem to be using the ToolStripItem.Click event.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.