By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,011 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Event Handling With Dynamic ToolStripMenu

P: n/a
The following method adds items to a toolstripmenu named colums

public void AddColumnMenu()
{
foreach (ColumnHeader column in messagesListView.Columns)
{

ToolStripMenuItem item =
(ToolStripMenuItem)columnsToolStripMenuItem.DropDo wnItems.Add(column.Text);
item.Checked = true;
item.CheckOnClick = true;

}
}

How do you add event handling for each menu item added? What I am
going to end up doing is allow the user to expand or remove a column
by clicking that column name in the columns menu.

May 17 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
What's wrong wiht good old ToolStripMenuItem.Click+=new EventHandler(<your
handler>); ?

Something like:

ToolStripMenuItem item =
(ToolStripMenuItem)columnsToolStripMenuItem.DropDo wnItems.Add(column.Text);
item.Checked = true;
item.CheckOnClick = true;
item.Click+=new EventHandler(HandleDynamicMenuClick);

}

void HandleDynamicMenuClick(object sender, EventArgs e)
{
ToolStripItem item=(ToolStripItem)sender;
MessageBox.Show("Selected menu " + item.Text);
}

<Am************@gmail.comha scritto nel messaggio
news:11********************@w5g2000hsg.googlegroup s.com...
The following method adds items to a toolstripmenu named colums

public void AddColumnMenu()
{
foreach (ColumnHeader column in messagesListView.Columns)
{

ToolStripMenuItem item =
(ToolStripMenuItem)columnsToolStripMenuItem.DropDo wnItems.Add(column.Text);
item.Checked = true;
item.CheckOnClick = true;

}
}

How do you add event handling for each menu item added? What I am
going to end up doing is allow the user to expand or remove a column
by clicking that column name in the columns menu.
May 17 '07 #2

P: n/a
Yep.. thats what I ended up doing. Im kind of a C# newb. Sorry for
the dumb question lol

On May 17, 10:32 am, "Laura T." <laura_...@yahoo.comwrote:
What's wrong wiht good old ToolStripMenuItem.Click+=new EventHandler(<your
handler>); ?

Something like:

ToolStripMenuItem item =
(ToolStripMenuItem)columnsToolStripMenuItem.DropDo wnItems.Add(column.Text);
item.Checked = true;
item.CheckOnClick = true;
item.Click+=new EventHandler(HandleDynamicMenuClick);

}

void HandleDynamicMenuClick(object sender, EventArgs e)
{
ToolStripItem item=(ToolStripItem)sender;
MessageBox.Show("Selected menu " + item.Text);
}

<AmericanGot...@gmail.comha scritto nel messaggionews:11********************@w5g2000hsg.go oglegroups.com...
The following method adds items to a toolstripmenu named colums
public void AddColumnMenu()
{
foreach (ColumnHeader column in messagesListView.Columns)
{
ToolStripMenuItem item =
(ToolStripMenuItem)columnsToolStripMenuItem.DropDo wnItems.Add(column.Text);
item.Checked = true;
item.CheckOnClick = true;
}
}
How do you add event handling for each menu item added? What I am
going to end up doing is allow the user to expand or remove a column
by clicking that column name in the columns menu.- Hide quoted text -

- Show quoted text -

Jun 15 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.