473,396 Members | 2,023 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,396 software developers and data experts.

Get ContextMenu Text of selected Item

Tyler Wiebe
First, here's a few things...

#1 -- The ContextMenu
Expand|Select|Wrap|Line Numbers
  1.  
  2. this.Tray_Icon_Context_Menu.MenuItems.Add("Open Tray", new System.EventHandler(Open_Tray));
  3. this.Tray_Icon_Context_Menu.MenuItems.Add("Close Tray", new System.EventHandler(Close_Tray));
  4. this.Tray_Icon_Context_Menu.MenuItems.Add("Set Default (" + Properties.Settings.Default.Disc_Drive + ")");
  5. this.Tray_Icon_Context_Menu.MenuItems.Add("Close Application", new System.EventHandler(Close_Application));
  6.  
#2 -- Updating The ContextMenu
Expand|Select|Wrap|Line Numbers
  1. private bool Update_Context_Menu(System.Collections.Generic.Lis t<string> Active_Disc_Drives)
  2. {
  3. this.Disc_Drive_Memory.Clear();
  4. this.Tray_Icon_Context_Menu.MenuItems[2].MenuItems.Clear();
  5.  
  6. if (!Active_Disc_Drives.Contains(Properties.Settings. Default.Disc_Drive))
  7. {
  8. Properties.Settings.Default.Disc_Drive = "";
  9. Properties.Settings.Default.Save();
  10. if (Properties.Settings.Default.Disc_Drive == "") Tray_Icon_Context_Menu.MenuItems[2].Text = ("Set Default (N/A)");
  11. }
  12.  
  13. foreach (string Active_Disc_Drive in Active_Disc_Drives)
  14. Disc_Drive_Memory.Add(Active_Disc_Drive);
  15. System.Windows.Forms.MenuItem Item = new System.Windows.Forms.MenuItem(Active_Disc_Drive, new System.EventHandler(Set_Default_Drive));
  16. Tray_Icon_Context_Menu.MenuItems[2].MenuItems.Add(Item);
  17.  
  18. if (Tray_Icon_Context_Menu.MenuItems[2].MenuItems[Tray_Icon_Context_Menu.MenuItems[2].MenuItems.IndexOf(Item)].Text == Properties.Settings.Default.Drive) Tray_Icon_Context_Menu.MenuItems[2].MenuItems[Tray_Icon_Context_Menu.MenuItems[2].MenuItems.IndexOf(Item)].Checked = true;
  19. else Tray_Icon_Context_Menu.MenuItems[2].MenuItems[Tray_Icon_Context_Menu.MenuItems[2].MenuItems.IndexOf(Item)].Checked = false;
  20. }
  21.  
  22. if (Tray_Icon_Context_Menu.MenuItems[2].MenuItems.Count == 0) Tray_Icon_Context_Menu.MenuItems[2].Enabled = false;
  23. else Tray_Icon_Context_Menu.MenuItems[2].Enabled = true;
  24.  
  25. return true;
  26. }
  27.  
#3 -- Setting The Default Disc Drive -- THIS IS WHERE THE PROBLEM IS

How do I get the text of the selected MenuItem (Disc Drive) on the Click Event? It'd be easy if the drive amount wouldn't change, I'd just need to make an event for each drive, but the thing is the amount can change.

So what I need is a way for each MenuItem to create its own Click Event, or a way to send the selected items text to a event like the following.
Expand|Select|Wrap|Line Numbers
  1. private void Set_Default_Drive()
  2. {
  3. Properties.Settings.Default.Disc_Drive = /* Insert Drive Name Here */;
  4. Properties.Settings.Default.Save();
  5.  
  6. Tray_Icon_Context_Menu.MenuItems[2].Text = "Set Default (" + Properties.Settings.Default.Drive + ")";
  7. }
  8.  
So if you can provide any help, it'd be much appreciated.
If you think I may have forgotten to add somethings to explain something, let me know.
Jul 27 '11 #1

✓ answered by Tyler Wiebe

Expand|Select|Wrap|Line Numbers
  1.         private void OnClick(object sender, System.EventArgs e)
  2.         {
  3.             System.Windows.Forms.MenuItem Clicked_Item = sender as System.Windows.Forms.MenuItem;
  4.             System.Console.WriteLine(Clicked_Item.Text);
  5.         }
  6.  

1 6573
Expand|Select|Wrap|Line Numbers
  1.         private void OnClick(object sender, System.EventArgs e)
  2.         {
  3.             System.Windows.Forms.MenuItem Clicked_Item = sender as System.Windows.Forms.MenuItem;
  4.             System.Console.WriteLine(Clicked_Item.Text);
  5.         }
  6.  
Jul 27 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Peter Moscatt | last post by:
I am having trouble understanding the methods for the Listbox from Tk. If I was to select at item in the list using a mouse click (have already created the bind event) - what method returns the...
1
by: Marc Jennings | last post by:
Hi There is probably a very simple answer to this, but I am not too familiar with the treeView control... I have a treeview control, populated from a database. I want to be able to get the...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
1
by: Karen Grube | last post by:
Hi! I'm using a standard server side ASP.Net listbox control on a web form. The page is basically various shades of green. The listbox itself has a pale green background and forest green text...
4
by: juststarter | last post by:
Hello, I have an aspx file where i've put a placeholder element. On load (page_load) i create dynamically an html table which contains a checkbox and a radiobuttonlist in each tablerow . The...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
6
by: George | last post by:
Hi all, How can I get the value stored from the selected item and subitems of a listview? Thanks in advance, George
0
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I have a listview that when I select an item, it populates a details view. I want to show the item that was selected in the listview by changing it to yellow. Trouble is, the selected item does not...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: sbandalli | last post by:
Hello, I have a Datagridview which has a combobox,and 2 textbox, The combobox is bound to a Datasource(Database Sql Server and the table name is Category) ,and Datagridview is not bounded to any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.