Click here to Skip to main content
15,901,205 members
Home / Discussions / C#
   

C#

 
GeneralRe: Reference problems Pin
Roger Stewart30-Mar-05 4:01
professionalRoger Stewart30-Mar-05 4:01 
GeneralFileSystemWatcher Pin
ppp00129-Mar-05 23:30
ppp00129-Mar-05 23:30 
GeneralRe: FileSystemWatcher Pin
Sebastian Schneider29-Mar-05 23:45
Sebastian Schneider29-Mar-05 23:45 
GeneralRe: FileSystemWatcher Pin
Chals30-Mar-05 4:37
Chals30-Mar-05 4:37 
Generalneed help to improve selected color filter logic Pin
montu337729-Mar-05 23:26
montu337729-Mar-05 23:26 
GeneralRe: need help to improve selected color filter logic Pin
Sebastian Schneider29-Mar-05 23:40
Sebastian Schneider29-Mar-05 23:40 
GeneralRe: need help to improve selected color filter logic Pin
montu337730-Mar-05 0:22
montu337730-Mar-05 0:22 
Generalcontext menu problems Pin
ekynox29-Mar-05 23:23
ekynox29-Mar-05 23:23 
G'day folks,

well i am attempting to get an understanding on how to create the menuitems in a context menu on the fly. So far I have managed to actually achieve the menu items being created for the context menu. However, I have stumbled across one problem. Which is that how does one go about enhancing the event handler for the context menu to invoke individual actions for each of the menu items.

I have included a snippet of my code. In this sample example, I created a button, which essentially adds 4 menu items based on strArray to the context menu. Any recommendations on how to improve the context menu event handler so that when I click on menu item "A" in the context menu, the message box pops up.

Any recommendations will be appreciated.

thanks in advance.

string[] strArray = {"A", "B","C","D"}; //declared as global

private void contextMenu1_Popup(object sender, System.EventArgs e)
{
try
{
MenuItem miClicked = (MenuItem)sender;
string item = miClicked.Index.ToString();
switch(item)
{
case "A":
MessageBox.Show("A");
break;
case "B":
MessageBox.Show("B");
break;
case "C":
MessageBox.Show("C");
break;
case "D":
MessageBox.Show("D");
break;
}
}
catch
{}
}
//creating menuitems for context menu when the Push Button is pressed.
protected void button1_Click(object sender, EventArgs e)
{
for(int i=0;i
GeneralRe: context menu problems Pin
Sebastian Schneider29-Mar-05 23:59
Sebastian Schneider29-Mar-05 23:59 
GeneralRe: context menu problems Pin
ekynox30-Mar-05 1:49
ekynox30-Mar-05 1:49 
GeneralRe: context menu problems Pin
Sebastian Schneider30-Mar-05 10:31
Sebastian Schneider30-Mar-05 10:31 
GeneralRe: context menu problems Pin
Sebastian Schneider30-Mar-05 10:36
Sebastian Schneider30-Mar-05 10:36 
GeneralRe: context menu problems Pin
ekynox1-Apr-05 1:11
ekynox1-Apr-05 1:11 
GeneralCompile and execute code Pin
lindiwe29-Mar-05 23:23
lindiwe29-Mar-05 23:23 
GeneralRe: Compile and execute code Pin
Stanciu Vlad29-Mar-05 23:43
Stanciu Vlad29-Mar-05 23:43 
GeneralRe: Compile and execute code Pin
Sebastian Schneider30-Mar-05 0:02
Sebastian Schneider30-Mar-05 0:02 
GeneralRe: Compile and execute code Pin
Kodanda Pani30-Mar-05 2:29
Kodanda Pani30-Mar-05 2:29 
Generalsystem class Pin
computer_eng29-Mar-05 22:50
computer_eng29-Mar-05 22:50 
GeneralRe: system class Pin
Sabry190529-Mar-05 23:55
Sabry190529-Mar-05 23:55 
GeneralRe: system class Pin
AristotleYu13-Jun-05 22:15
AristotleYu13-Jun-05 22:15 
Generalclose a dialog box when a text box has focus Pin
steve_rm29-Mar-05 22:05
steve_rm29-Mar-05 22:05 
GeneralRe: close a dialog box when a text box has focus Pin
Stanciu Vlad29-Mar-05 22:30
Stanciu Vlad29-Mar-05 22:30 
GeneralRe: close a dialog box when a text box has focus Pin
Luis Alonso Ramos30-Mar-05 7:49
Luis Alonso Ramos30-Mar-05 7:49 
GeneralRe: close a dialog box when a text box has focus Pin
S. Senthil Kumar30-Mar-05 19:30
S. Senthil Kumar30-Mar-05 19:30 
Generalwin32 datatype in C#.NET Pin
Babarsaeed29-Mar-05 22:00
Babarsaeed29-Mar-05 22:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.