473,320 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do you get the selected ContextMenu item?

Hi

I have a contextmenu that is created by looping through a datarow view
and in the foreach loop I have this:

ToolStripMenuItem menuItem = new ToolStripMenuItem();
menuItem.Text = row["Name"].ToString();
menuItem.Name = row["StockCategoryId"].ToString();
menuItem.Click += new EventHandler(MoveTo_Click);
moveToMenuItem.DropDownItems.Add(menuItem);

The MoveTo_Click event performs something based on what
ToolStripMenuItem was chosen.

How do I get what this chosen item was?

Thanks for your time
Peter

Mar 25 '06 #1
2 20754
Hi Peter
You can use sender parameter of MoveTo_Click :

void MoveTo_Click(object sender, EventArgs e)
{
ToolStripMenuItem m = (ToolStripMenuItem)sender;

MessageBox.Show(m.Text);

}
You can use Tag property of ToolStripMenuItem to store RowIndex or
PrimaryKey to better finding current row.

A.Hadi

Mar 25 '06 #2
Thanks for the reply Abu

Never realised the object could be casted like that!

The tag property was going to be my second question :) Thanks

Peter

Mar 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: John Scott | last post by:
I've been looking around for a solution to this for a while. I just want to bold the selected item in a radio button list from the client-side using javascript. The HTML generated for the list...
0
by: Webermax | last post by:
Hello, I want to retrieve the index of the selected item in a context menu synchronously. I coded something like this : MyContextMenu mcm; mcm = new MyContextMenu (); mcm.MenuItems.Add (new...
2
by: billyb | last post by:
My listview has two columns: Email Address & Email Address Type. I've figured out how to populate it, but now I'm having trouble figuring out how to properly use the SelectedItems to get at the...
2
by: baret bonden | last post by:
Trying to return a selected listbox item to another form .tried lots of ways; defining public variables and passing those as well as textboxes ..I' m able to display the chosen item on it's form...
0
by: Jaime Lucci | last post by:
Hi everyone! I'm using an ActiveListBar control which is a COM Component. I´ve associated a context menu to it by the show method of my context menu: contextmenu.Show(activelistvar,position),...
0
by: NeilS | last post by:
Hi all. I'm a newbie at VB.net, so please forgive me if this is well documented somewhere. I've found some sample code on the MS site for iterating over each unread item in the Inbox, and...
0
by: goran.strand | last post by:
In my Default.aspx I have a Menu control (System.Web.UI.WebControls.Menu) with some static menu items. When I click on a menu item, the navigate URL contains another aspx page that I load in an...
4
by: Brett Wesoloski | last post by:
I am having a bit of a problem getting the current value of the checkbox list. I have tried using the selected value as I thought that would give me the current value of the check box but it...
1
mutanic
by: mutanic | last post by:
Hi Bytes, I'm trying to get SUM of column "Price" base on selected item in column "Item". I've got no idea how to solve this without have to use sort & group function through SPD. This has to be a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.