Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > How to get the current selected ContextMenuStripItem in a ContextMenuStrip
 

How to get the current selected ContextMenuStripItem in a ContextMenuStrip


Hi all,

I am facing this problem. I have a ContextMenuStrip attached on a control. As I right click on that control the ContextMenuStrip appears. So far so good, but when I press down arrow key or up arrow key I am unable to find the current selected ContextMenuStripItem. I need to know which ContextMenuStripItem is currently selected when one presses the up arrow and down arrow.

Please help me in this.
Thanks in advance.

Thanks and regards,

pankbug2000  Wednesday, July 30, 2008 7:19 AM
tried the following code and it seems to work...

Code Snippet

public Form1()
{
InitializeComponent();

this.contextMenuStrip1.Items.Add("First");
this.contextMenuStrip1.Items.Add("Second");
this.contextMenuStrip1.Items.Add("Third");

this.contextMenuStrip1.Opening += new CancelEventHandler(contextMenuStrip1_Opening);
}

void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
this.contextMenuStrip1.Items[1].Select();
}

hth,
Lior.
Lior Salem  Thursday, August 07, 2008 11:56 AM

Hi all,

Finally I resolved the problem but now I am stuck with another. I am trying to set focus on a ContextMenuStripItem and since there is no such method, I am calling the method Select(). But this method is not working properly.

I want to show that ContextMenuStripItem as selected.


Thanks and regards,

pankbug2000  Wednesday, July 30, 2008 12:59 PM
tried the following code and it seems to work...

Code Snippet

public Form1()
{
InitializeComponent();

this.contextMenuStrip1.Items.Add("First");
this.contextMenuStrip1.Items.Add("Second");
this.contextMenuStrip1.Items.Add("Third");

this.contextMenuStrip1.Opening += new CancelEventHandler(contextMenuStrip1_Opening);
}

void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
this.contextMenuStrip1.Items[1].Select();
}

hth,
Lior.
Lior Salem  Thursday, August 07, 2008 11:56 AM

You can use google to search for other answers

Custom Search

More Threads

• Adding Fields
• Change the scrollbar
• To Avoid Sending Passwords over the Network in Plain Text
• open web appl from win all
• How to Create Simple MDI Forms
• Terrarium 1.2 Server Available
• Soap exception while inserting animal in terrarium
• Deploying Windows Applications with Crystal Reports IN VS2005
• Host XSD Designer on Winform application
• What's VSDeisgner ?